Archive

Archive for the ‘Uncategorized’ Category

The New Hype: Top Shelf Project for building Windows Services

January 30, 2012 Leave a comment

Lately my coder compadres have been all a flutter about something called Top-Shelf-Project, an open source project for building windows services for .NET or Mono platforms.

What’s so great about it? I don’t know. I’m trying to find out.  I’ll be back in an hour…

Okay, it’s been more than an hour, but I had to go refill my iced espresso and space out for a minute or two.

Here’s what I’ve found out:

The Top Shelf project allows you to deploy behavior in a similar fashion to a traditional Windows Service, but without the need to create an actual Windows Service project type – a Console Application will suffice, and without all the scaffolding that a regular Windows Service project requires.  You can just run a short bit of fluent configuration in your Console App’s Main routine to configure a regular .NET type as a service. You then have the option to debug it as a Console App (which is a bit easier than having to install and then attach to a traditional Windows Service).

So that’s three nice things there:

  1. less scaffolding,
  2. easier debugging options
  3. fluent style configuration.

That’s a good start.

There’s a few more reasons to dig it besides. Top Shelf bakes some additional goodness into its fluent Host Configuration – namely some convenient command line installation parameters.  Its sort of like magic. I had to check out the source code to see how they did this just to convince myself that it would really work.  Its baked into the host configuration routine.  It looks for command line arguments like “Install” and then handles the nitty gritty of actually installing your console app as a service.

So you build your console app and then just run it from the command line with the “install” argument.

like: c:\boogersugarservice.exe install

The traditional way of installing a Windows Service these days is really not so bad. I wrote a powershell script to uninstall, copy and reinstall a windows service recently – using installutil.  No biggie.  This doesn’t change that scenario all that much, but at least its self-contained and you don’t even need to get a separate utility involved.  Any time even a single step can be eliminated from a deployment procedure my brain releases some happiness chemicals.

Then there’s this whole SHELVING concept.  First of all, what’s up with this metaphor?  I’ve gotten used to using this term in the context of TFS source control and spent a few minutes fumbling about trying to disambiguate that from the meaning in this context.

I could be wrong here, but best guess is you can deploy and startup a new service as easily as throwing a book on a shelf – something like that? Maybe? No?  Well whatever.

Basically shelving involves the use of a TopShelf Service Host. The intention of the host is to allow you to deploy and re-deploy services and have them auto-magically stop/uninstall/reinstall/start in a similar fashion to when you modify the web.config file of a site in IIS and IIS auto-magically knows to recycle the app pool and reload the config.

I haven’t tried this out yet. I’ve been perusing the discussion forums and seeing a fair amount of trouble with production implementations of this.  Makes me a little nervous. But I’ll have to try it out for myself and see.  I will report the results in a future post.

Advertisements
Categories: Uncategorized

VS2010 Error: Unable to start debugging on the web server

November 21, 2011 Leave a comment

If ever you should find yourself confronted with the following error in VS2010 (or its ancestors):

“Unable to start debugging on the web server”

It could be because the msvsmon.exe process has been terminated by some unfortunate circumstances.

This will drive you insane until you sort it out, so quickly read this:

http://msdn.microsoft.com/en-us/library/xf8k2h6a.aspx

Basically, you need to make sure that the Remote Debugging Monitor, msvsmon.exe is running.  Find VS2010 in your programs menu and look for the Visual Studio 2010 Remote Debugger under Visual Studio Tools.  Read that article for configuration details. In my case, simple browsing into the x64 directory and executing the msvsmon.exe fixed the problem.  This is something I normally take for granted when debugging in Visual Studio.  I created my own problem here because I actually wrote a powershell script to kill the msvsmon.exe process when re-initializing my debug environment.  Why?  Because I was trying to identify the source of some session cache re-initialization issues and thought that little bugger might have had a hand in it.  Still not sure if that was the case, but I do know that I need to make sure that I restart this after I kill it.

Categories: Uncategorized

Bulk Rename Operation in TFS using Powershell

March 25, 2011 Leave a comment

If the structure of your TFS source control requires an overhaul this may help.

Lift With Your LegsFirst if you haven’t already, install the TFS Power Tools. Make sure you find the most recent release.

Here is a link to the most recent version to date: http://visualstudiogallery.msdn.microsoft.com/c255a1e4-04ba-4f68-8f4e-cd473d6b971f

During installation be sure to install the TFS Cmdlets for Powershell.

If you’ve never used Powershell before fire up a PS Console from the shortcut found under TFS Power Tools in your program menu.

Then set the execution policy by typing the following:

Set-ExecutionPolicy RemoteSigned

OK. Now you’re ready to do some damage. 

SERIOUSLY careful with this!

You don’t want to mess up your repository any more than it already is.
The following snippet is just an example of something you could do, but is not meant to be used as is.  You will need to modify it to suit your requirements.

In my situation I had created about 25+ separate directories for different website projects, each with their own set of branches, Dev, Main, etc.  It looked something like this:

WebSite1/Dev/…
WebSite2/Dev/…
WebSite3/Dev/…

and so on.  I realized I would have to create an additional directory under “Dev” which was the root of the branch to contain each website.   It would have to be modified to look more like this:

WebSite1/Dev/WebSite/…
WebSite2/Dev/WebSite/…
WebSite3/Dev/WebSite/…

So, first I tried to use the Source Control Explorer “Move” command through the GUI.  That didn’t work too well. SCE didn’t seem to want me to move all the files at once in a drag and drop operation and I didn’t want to have to painstakingly drag each directory individually.

Powershell to the rescue…

The Powershell CmdLets for TFS installed with the Power Tools include one item called:

Get-TfsChildItem

This allows you to recursively enumerate source controlled items.

Try this — Don’t worry it’s safe:

Get-TfsChildItem $/YourProject/*  -Recurse

So, from there we can get the server paths of everything in source control. Combine them with some Where-Object, Select-Object and foreach in Powershell along with the TFS command line utility, TF.exe and we have the makings of a solution.

$sites = “WebSite1”, “WebSite2”, “WebSite3”

foreach($item in $sites){

tf get $/MyProject/$item/Dev/

write-host “Renaming directories”

Get-TfsChildItem $/MyProject/$item/Dev/* -Folder | Where-Object { -not $_.ServerItem.Contains(“/WebSite”)  }| Select-Object ServerItem | foreach { tf rename $_.ServerItem $_.ServerItem.Replace(“/Dev/”,”/Dev/WebSite/” ) }

Write-Host “About to checkin”

tf checkin $/MyProject/$item/Dev/ /recursive /noprompt

Write-Host “Renaming root items”

Get-TfsChildItem $/MyProject/$item/Dev/*.*  -Recurse | Where-Object { -not $_.ServerItem.Contains(“/WebSite”)  }| Select-Object ServerItem | foreach { tf rename $_.ServerItem $_.ServerItem.Replace(“/Dev/”,”/Dev/WebSite” ) }

Write-Host “About to checkin”

tf checkin $/MyProject/$item/Dev/ /recursive /noprompt
}

Categories: Uncategorized