Daniel Dittenhafer

Develop With Dedication & Improved Interfaces

  Home  |   Contact  |   Syndication    |   Login
  7 Posts | 0 Stories | 18 Comments | 0 Trackbacks

News

Article Categories

Archives

Post Categories

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";
  3.  
  4. $BuildArgs = @{
  5.  FilePath = $MsBuild
  6.  ArgumentList = $SlnFilePath, "/t:rebuild", ("/p:Configuration=" + $Configuration), "/v:minimal"
  7.  RedirectStandardOutput = $BuildLog
  8.  Wait = $true
  9.  }
  10.  
  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

Feedback

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

# re: Automating a Visual Studio Build with PowerShell - Part 1 10/17/2012 6:41 AM dissertation-writing-help.org
I was browsing internet and found your blog. The author did a great job. I will subscribe to your RSS feeds.

# re: Automating a Visual Studio Build with PowerShell - Part 1 11/28/2012 9:36 AM vesr
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


# re: Automating a Visual Studio Build with PowerShell - Part 1 6/20/2013 1:30 AM Bhupendra S Mudaliar
HI,

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.

Regards,
Bhupendra

Post A Comment
Title:
Name:
Email:
Comment:
Verification: