Geeks With Blogs
Daniel Dittenhafer Develop With Dedication & Improved Interfaces

One of the several hats I wear at work is one of configuration manager for the internal data management application my employer uses. This app currently has 11 solutions of active code which need to be built whenever we release to the QA environment. The QA releases typically occur a minimum of 3 times per month and take approximately 30 minutes from source control "Get Latest" to the final step of the deployment onto the QA servers.

A few years ago, my team automated the post-build deployment steps using a CMD batch script, but the build process has continued to be done manually by loading each solution, and rebuilding along with some logistical steps of pre-cleaning and saving the build log. After participating in the 2011 Scripting Games, I started thinking that I could use PowerShell to automate the build process and cut the QA release time significantly. I've started developing some scripts to make this happen and through this article would like to start sharing some of the useful functions.

First I decided to use MSBUILD.EXE as the basis for the builds. I know TFS Build Server uses this tool also, and it just makes sense for any Visual Studio build process. My app is still using Visual Studio 2005 and .Net Framework v2 (I hope to upgrade to VS2008 later this year), so my efforts revolve around the v2.0.50727 flavor of MSBUILD.EXE, but I imagine much of my research is applicable to v3.5 and v4 as well.

I found a useful article and response on StackOverflow which helped me with some of the early development of my script, but then I went off in my own direction. I found that I could use the "splatting" technique and the Start-Process command to improve the interaction with MSBUILD and have some additional control over the build log output, as shown below with a command to rebuild the specified solution.

  1. # Local Variables
  2. $MsBuild = $env:systemroot + "\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe";
  4. $BuildArgs = @{
  5.  FilePath = $MsBuild
  6.  ArgumentList = $SlnFilePath, "/t:rebuild", ("/p:Configuration=" + $Configuration), "/v:minimal"
  7.  RedirectStandardOutput = $BuildLog
  8.  Wait = $true
  9.  }
  11. # Start the build
  12. Start-Process @BuildArgs

I've been developing a PowerShell Module to wrap all the MSBuild code, so the above code is wrapped in the function Build-VisualStudioSolution which takes $SlnFilePath, $Configuration and $BuildLog as parameters. With that said, I plan to have a series of posts on the topic of Visual Studio build automation with PowerShell, thereby making this Part 1. Stay tuned.... once the module is more put together and ready for public consumption, I hope to make it available for download.

Posted on Friday, May 20, 2011 1:48 PM PowerShell , Visual Studio | Back to top

Comments on this post: Automating a Visual Studio Build with PowerShell - Part 1

# re: Automating a Visual Studio Build with PowerShell - Part 1
Requesting Gravatar...
please add more notes on build in powershell automatic script.
Left by neeraj jha on Feb 24, 2012 2:24 AM

# re: Automating a Visual Studio Build with PowerShell - Part 1
Requesting Gravatar...
I was browsing internet and found your blog. The author did a great job. I will subscribe to your RSS feeds.
Left by on Oct 17, 2012 6:41 AM

# re: Automating a Visual Studio Build with PowerShell - Part 1
Requesting Gravatar...
I'd appreciate to chat about several illusion when it comes to this subject, since it's pretty essential for us to be aware of something about how to avoid such a hard challenge later on. Thank you guys for blogging this information and facts. I like the some people's feelings and it's a enjoyment to certain it. Take a moment to comment on my articles, cause i am not a a winning player. le meilleur casino en ligne
Left by vesr on Nov 28, 2012 9:36 AM

# re: Automating a Visual Studio Build with PowerShell - Part 1
Requesting Gravatar...

We are doing automation of Azure. Task is to automate the Azure package generation through TFS build.
If any blogs or other materials will be helpful.

Left by Bhupendra S Mudaliar on Jun 20, 2013 1:30 AM

Your comment:
 (will show your gravatar)

Copyright © Dittenhafer Solutions | Powered by: