Build VisStudio projects from PowerShell Console

I like being able to build projects and solutions from the command line.  That is easy enough to do from a “Developer Command Prompt”, as that sets up all the necessary environment variables (via vsvars32.bat).

However, I have long preferred TakeCommand/TCC to cmd.exe, so I created a .bat file for TakeCommand that called vsvars32 (if necessary), then launched MSBuild with the appropriate command line.  The .bat allowed certain parameters – Config and Target – to be set.  Unfortunately, if you set one, you had to set them all.

I wanted the same functionality in PowerShell, and thought I would have to translate vsvars32.bat to a .ps1 file.  Naturally, someone has already done that.  Even better, someone created a way to run a .bat file, extract the resulting environment vars to a temp file, and set those environment vars in the PowerShell session.  Much better – no having to keep a .ps1 in sync with a .bat!

With the power of PowerShell named params and default values, it is easy to create flexible functions that don’t rely on the position of a parameter for its meaning.

Here is the basic help:
[master +1 ~0 -1 !] > get-help Build-Solution


Build-Solution [-Proj] <string> [[-Config] <string>] [[-Target] <string>]



The Config var defaults to “Debug”, and the Target var defaults to “Build”.

> bld12 gloogle.sln

> bld12 flankle.sln –Target REBUILD

msbld12 depends on Invoke-CmdScript.  Download the attached files and rename to *.ps1.

msbld12 Invoke-CmdScript

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you human? * Time limit is exhausted. Please reload CAPTCHA.

Protected with IP Blacklist CloudIP Blacklist Cloud