Running MSBuild from Visual Studio

May 31st, 2007

I make use of MSBuild on every project I develop. (see 7 Steps to MSBuild) What I have always wanted to do is run MSBuild from within Visual Studio like you can do with Ant scripts in the popular Java IDEs. MSBuild comes with the .NET 2.0 runtime and is a Microsoft utility yet there really are no tools to do what I want. But today I had an idea of adding MSBuild as an External Tool.

What I did was add the new definition for MSBuild and set the arguments to point to the standard name I am using, build.proj, with reasonable default values for the Target and Configuration. The result is the image displayed below.


Now I can run my custom build script from within Visual Studio and have the results shown in the Output window. I specifically have it prompt me for the arguments so that I can selectively change the target from Build to whatever I want as well as change the value for the Configuration property or add more properties which takes a list of semicolon delimited properties. The final and very important detail is setting the Initial Directory to the $(SolutionDir) property.

I got the idea after watching the SubSonic videos where Rob Conery has custom tools set up for calling sonic.exe with different arguments. What I would do different than Conery is add the SubSonic commands to the MSBuild script as targets such as RegenerateCode and VersionDb so that I can run it with the exact same commands each time.

One Response to “Running MSBuild from Visual Studio”

  1. Brennan’s Blog » Blog Archive » Web Deployment Projects in Visual Studio 2008 Says:

    [...] Below is my main build.proj script which assumes the website is in a folder named Website and the Web Deployment project is in a folder called Website_deploy. It creates a zip file with three folders: Assemblies, ThirdParty and Website. The Assemblies folder holds the output files from the class library while the ThirdParty folder holds the pre-built assemblies referenced by the class library. Finally the Website folder holds the output generated by the Website Deployment project. To learn more about working with MSBuild, you can read 7 Steps to MSBuild and to learn how to make better use of Web Deployment Projects you can read Post Build Deployments with MSBuild. Finally, to learn how to easily to run the MSBuild script in your root Solution folder you can read Running MSBuild from Visual Studio. [...]