Deploying Console Apps via MSBuild

VS2010 and MSBuild don’t provide a good way to deploy windows apps using continuous integration (especially to different environments). Over the past couple days I’ve wasted a lot of time manually deploying my apps to test them on dev. Brian Gansemer has talked about creating hooks for deploying ClickOnce apps as part of the build process, but I wanted to keep my apps as regular console apps. Here is the solution I came up with to automatically deploy my project.

Below is a screenshot of a sample eCommerce solution we use internally to demonstrate architecture patterns.

Screenshot of a sample eCommerce solution we use internally to demonstrate architecture patterns.

MSBuild dumps all of a solution’s client apps and their dlls/files in a single folder, so deploying from that solution was not going to work. I had to create a new solution that only contained the project for the app I want to deploy. You’ll notice the warning symbols placed on references to projects that are not in the new solution (Contracts, DataContracts, and eCommerceServiceBase). If the eCommerce solution is built before ConsoleDeploymentSolution, ConsoleDeploymentSolution will get the updated .dlls. However, if building the “master” solution before the console solution is not possible in your environment, you will need to add the referenced projects to your console solution.

If building the "master" solution before the console solution is not possible in your environment, you will need to add the referenced projects to your console solution.

To create the deployment I added this to my Post-Build event command line so it will only deploy in the ConsoleDeploymentSolution solution and the Debug configuration:

if “$(SolutionName)” == “ConsoleDeploymentSolution” if “$(ConfigurationName)” == “Debug” xcopy /Y /E “$(TargetDir)*.*” \\Fileshare\DemoConsoleApp

Post-build event

If you aren’t using MSBuild for continuous integration, you don’t need to follow the next steps. Building the ConsoleDeploymentSolution on your local machine will perform the file copy and set up an automatic deployment for your console application.

If, however, you are using MSBuild, you’ll need to create a Build definition for the new solution.

If you are using MSBuild, you'll need to create a Build definition for the new solution.

I then set the build to trigger on check-in.

Set the build to trigger on check-in.

I also had to change the default workspace so it wouldn’t interfere with my master solution.

I also had to change the default workspace so it wouldn’t interfere with my master solution.

Save this new build and now whenever you check in code, your console app will be deployed.

I found this page that lists out a bunch more properties you can access in the post build event command line:

Macros for Build Commands and Properties: http://msdn.microsoft.com/en-us/library/c02as0cs(v=VS.100).aspx

author avatar
Adam Miller

Related posts