Integrating MSBuild into Visual Studio

爱⌒轻易说出口 提交于 2019-12-20 09:49:26

问题


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:


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.




回答2:


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




回答3:


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.




回答4:


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.




回答5:


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




回答6:


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

How To: Insert Custom Process at Specific Points During Build




回答7:


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/




回答8:


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



回答9:


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.




回答10:


I use the msbuild template to intergrate with visual studio

http://msbuildtemplate.codeplex.com/



来源:https://stackoverflow.com/questions/1497344/integrating-msbuild-into-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!