visual-studio 将 MSBuild 集成到 Visual Studio

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1497344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 11:03:36  来源:igfitidea点击:

Integrating MSBuild into Visual Studio

visual-studiovisual-studio-2008msbuild

提问by Alex Angas

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

我是一名独立开发人员,运行 Visual Studio 2008 并研究 MSBuild 以改进我的构建过程。

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.

到目前为止,我发现的几乎所有教程都有大量关于编写构建文件的信息。但是,我在找出如何将 MSBuild 集成到 Visual Studio 时遇到了很多麻烦。也许 MSBuild 只与 CruiseControl 之类的东西一起使用,但作为一个开发人员,这对我来说太过分了。

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

构建文件应该在 Visual Studio 项目中的哪个位置,我如何从 IDE 中运行它?

采纳答案by si618

Visual Studio executes MSBuild automatically for projects it supports.

Visual Studio 为其支持的项目自动执行 MSBuild。

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.

如果右键单击一个项目并将其卸载,则可以在 Visual Studio 中对其进行编辑。重新加载(再次右键单击项目),强制(重新)构建以测试您的更改。另一种方法是在外部编辑器中编辑项目文件,Visual Studio 将检测保存并提供为您重新加载项目。

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 Tasksand MSBuild Extension Pack.

听起来您走在正确的轨道上,如果您正在考虑编写目标或自定义 MSBuild 任务,请花时间将它们与您当前的项目分开,以便您可以重用它们。不过不要重新发明轮子,两个主要的互补 MSBuild 项目是MSBuild Community TasksMSBuild 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 itto automate more of your build process, just depends on what you want. Either approach could also be driven from the command line.

更新:从您对 Mitch 回答的评论来看,您可能还需要考虑向项目添加新的配置元素或自定义属性。新的 MSBuild 配置(不是默认的调试/发布)可以运行单元测试、构建文档或任何你想要自动化的东西。自定义 MSBuild 属性将允许您使用正常的调试/发布配置并扩展它以自动化更多的构建过程,这取决于您想要什么。这两种方法也可以从命令行驱动。

回答by Mitch Wheat

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

正如其他人所指出的,当您安装 Visual Studio 时,MSBuild 已经可用。

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

如果要集成到 VS2008:从 Visual Studio 运行 MSBuild

回答by Enrico Campidoglio

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

MSBuild 是 Visual Studio用来处理项目中包含的文件的构建引擎
Visual Studio 项目文件本身(例如,对于 C# 为 **.csproj*,对于 VB 为.vbproj,例如)实际上是每次构建项目时都会运行的 MSBuild 脚本。

回答by fmuecke

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

可以使用当前的 .vcproj 文件通过 MSBuild 构建项目。但是,由于不直接支持 MSBuild(至少对于 vc++),因此使用 vcbuild(在内部)。在 VS2010 中,所有项目文件都是基于 MSBuild...

回答by Mike Two

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

这是一篇关于 msbuild 团队的一些简单扩展点的旧文章

How To: Insert Custom Process at Specific Points During Build

如何:在构建期间的特定点插入自定义流程

回答by Bart Janson

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/

另外,不要忘记您可以使用 MSBuild SideKick 来开发和调试您的(本地)msbuild,可在http://www.attrice.info/msbuild/免费获得

回答by dove

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

您的 .csproj 文件是一个 MSBuild 文件。所以你实际上已经在使用它了。

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.

如果您只是希望编辑您的项目构建文件,那么您可以使用 IDE 来编辑一些设置,例如构建前和构建后操作,或者通过卸载项目并右键单击和编辑来编辑 Xml 本身。

回答by Ryu

I use the msbuild template to intergrate with visual studio

我使用 msbuild 模板与 Visual Studio 集成

http://msbuildtemplate.codeplex.com/

http://msbuildtemplate.codeplex.com/

回答by Gerrie Schenck

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.

我建议您将 msbuild 称为构建后步骤。然后,您可以将构建脚本放在解决方案中的某个位置并调用它。

<windowsdir>\Microsoft.NET\Framework\v3.5\MSBuild.exe c:\temp\MyProject\mybuildfile.proj

回答by Bjorn

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.

最简单的方法可能是使用构建后步骤调用您的自定义构建脚本。右键单击项目,选择“构建事件”并从那里使用您的自定义 msbuild 文件调用 msbuild。