views:

1035

answers:

10

I'm a solo developer running Visual Studio 2008 and looking into MSBuild to improve my build process.

Almost all of the tutorials I've found so far have plenty of information about writing a build file. However I'm having a lot of trouble finding out how to integrate MSBuild into Visual Studio. Maybe MSBuild is only used with something like CruiseControl but that's overkill for me as a single developer.

Where should the build file live in a Visual Studio project and how can I run it from within the IDE?

+1  A: 

Your .csproj file is a MSBuild file. So you are actually using it already.

You may of course wish to create a separate build file to have more control, especially within a continuous integration or nightly build say.

If you simply wish to edit your project build file then you can use the IDE to edit some settings such as pre and post build actions or edit the Xml itself by unloading project and right click and editing.

dove
Am I going overboard by wanting a separate build file if I'm not using CI or nightly builds? The build is a little complex that's all.
Alex Angas
@Alex you're not going overboard at all. the biggest cost is the learning curve and it sounds like you're on that road already so i'd say it's worth the learning investment to do it with a separate build file. look at build extensions and even attrice build software if you can afford to pay as it may help you.
dove
+1  A: 

MSBuild is the build engine used by Visual Studio to process the files included in a project.
The Visual Studio project files themselves (*.csproj for C#, and .vbproj for VB, for example) are in fact MSBuild scripts that are run every time you build a project.

Enrico Campidoglio
+1  A: 

You can use your current .vcproj files to build your project with MSBuild. However, as MSBuild is not directly supported (at least for vc++) vcbuild is used instead (internally). In VS2010 all project files are MSBuild based...

fmuecke
A: 

I'd suggest you call msbuild as a post build step. Then you can put your build script somewhere in your solution and call it.

<windowsdir>\Microsoft.NET\Framework\v3.5\MSBuild.exe c:\temp\MyProject\mybuildfile.proj
Gerrie Schenck
Yuck. BeforeBuild or AfterBuild targets are much better hooks.
Si
@Si: On the link given by @Mike Two the BeforeBuild and AfterBuild targets are supposedly for legacy support? http://blogs.msdn.com/msbuild/archive/2005/11/23/496396.aspx
Alex Angas
@Gerrie: Doesn't that mean I'd be building twice then?
Alex Angas
BeforeBuild and AfterBuild are not for legacy support, that post is incorrect. (Yeah I know its on the MSBuild blog itself, but trust me on this).
Sayed Ibrahim Hashimi
A: 

The easiest way is probably to invoke your custom build script using a post-build step. Right click project, choose "Build Events" and call msbuild with your custom msbuild file from there.

Bjorn
But then am I not building twice? (Once in VS and once in MSBuild?)
Alex Angas
+10  A: 

Visual Studio executes MSBuild automatically for projects it supports.

If you right click on a project and unload it, you can then edit it in Visual Studio. Reload (right click on project again), force a (re)build to test your changes.

Sounds like you're on the right track, and if you are considering writing Targets or custom MSBuild Tasks, take the time to separate them from your current project so that you can re-use them. Don't re-invent the wheel though, the two main complementary MSBuild projects are MSBuild Community Tasks and MSBuild Extension Pack.

Update: Judging from your comment on Mitch's answer, you might also want to consider adding a new Configuration element or custom properties to a project. A new MSBuild Configuration (something other than the default Debug/Release) could run unit tests, build documentation, or whatever you want automated. A custom MSBuild property would allow you to use normal Debug/Release Configuration and extend it to automate more of your build process, just depends on what you want. Either approach could also be driven from the command line.

Si
+2  A: 

As others have noted, MSBuild is already available when you install Visual Studio.

If you want to integrate into VS2008: Running MSBuild from Visual Studio

Mitch Wheat
I'd like to right-click on a build file and select "Build". This is getting there.
Alex Angas
+1  A: 

This is an older article about some simple extension points from the msbuild team

How To: Insert Custom Process at Specific Points During Build

Mike Two
+1  A: 

Also, don't forget you can use the MSBuild SideKick for developing and debugging your (local) msbuilds, available for free at http://www.attrice.info/msbuild/

Bart Janson
Oooh that looks handy.
Alex Angas
A: 

I use the msbuild template to intergrate with visual studio

http://msbuildtemplate.codeplex.com/

Ryu