Integrating MSBuild into Visual Studio



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?

10 ответов


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. An alternative is to edit the project file in an external editor and Visual Studio will detect saves and offer to reload the project for you.

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.


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

  • Я хочу щелкнуть правой кнопкой мыши файл сборки и выбрать «Сборка». Это приближается.

    Alex Angas01 октября 2009, 09:27

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.

  • Но разве я не строю дважды? (Один раз в VS и один раз в MSBuild?)

    Alex Angas01 октября 2009, 09:28

Также не забывайте, что вы можете использовать MSBuild SideKick для разработки и отладки ваших (локальных) сборок msbuild, который доступен бесплатно по адресу


Я бы посоветовал вам вызвать msbuild на этапе пост-сборки. Затем вы можете поместить свой сценарий сборки где-нибудь в своем решении и вызвать его.

 <windowsdir>\Microsoft.NET\Framework\v3.5\MSBuild.exe c:\temp\MyProject\mybuildfile.proj
  • 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 Hashimi01 октября 2009, 20:18
  • @Gerrie: Разве это не значит, что тогда я буду строить дважды?

    Alex Angas01 октября 2009, 09:32
  • @Si: On the link given by @Mike Two the BeforeBuild and AfterBuild targets are supposedly for legacy support?

    Alex Angas01 октября 2009, 09:30
  • Yuck. BeforeBuild or AfterBuild targets are much better hooks.

    si61830 сентября 2009, 10:55

Вы можете использовать текущие файлы .vcproj для сборки проекта с помощью MSBuild. Однако, поскольку MSBuild напрямую не поддерживается (по крайней мере, для vc ++), вместо него используется vcbuild (внутренне). В VS2010 все файлы проекта основаны на MSBuild ...


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.


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.

  • @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.

    dove01 октября 2009, 09:49
  • 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 Angas01 октября 2009, 09:29

Я использую шаблон msbuild для интеграции с Visual Studio


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

How To: Insert Custom Process at Specific Points During Build