Visual Studio 构建步骤与 MSBuild 构建步骤之间的差异

Differences between Visual Studio Build step and MSBuild Build step

我正在创建一些构建定义,我看到 Visual Studio 构建步骤和 MSBuild 构建步骤之间的唯一区别是 VS 构建步骤将 visual studio 版本添加到构建中。

有人可以解释更多差异吗?

很少。这两个任务是开源的,它们似乎都或多或少地做着相同的事情。

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/msbuild?view=vsts

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/visual-studio-build?view=vsts

他们几乎和丹尼尔提到的一样。主要区别与您所发现的一样:Visual Studio 构建步骤将 Visual Studio 版本添加到构建中。

Should I use the Visual Studio Build step or the MSBuild step?

If you are building a solution, in most cases you should use the Visual Studio Build step. This step automatically:

  • Sets the /p:VisualStudioVersion property for you. This forces MSBuild to use a particular set of targets that increase the likelihood of a successful build.

  • Specifies the MSBuild version argument.

In some cases you might need to use the MSBuild step. For example, you should use it if you are building code projects apart from a solution.

我看到这个问题是关于两个构建任务的。

但是由于 Google 会在人们搜索 MSBuild 和 VS Build(不是 Buildpipeline 任务)之间的区别时突出显示这个问题,所以我想添加来自 Microsoft 的引用:

Visual Studio builds vs. MSBuild.exe builds

There are some significant differences between when projects build in Visual Studio vs. when you invoke MSBuild directly, either through the MSBuild executable, or when you use the MSBuild object model to start a build. Visual Studio manages the project build order for Visual Studio builds; it only calls MSBuild at the individual project level, and when it does, a couple of Boolean properties (BuildingInsideVisualStudio, BuildProjectReferences) are set that significantly affect what MSBuild does. Inside each project, execution occurs the same as when invoked through MSBuild, but the difference arises with referenced projects. In MSBuild, when referenced projects are required, a build actually occurs; that is, it runs tasks and tools, and generates the output. When a Visual Studio build finds a referenced project, MSBuild only returns the expected outputs from the referenced project; it lets Visual Studio control the building of those other projects. Visual Studio determines the build order and calls into MSBuild separately (as needed), all completely under Visual Studio's control.

Another difference arises when MSBuild is invoked with a solution file, MSBuild parses the solution file, creates a standard XML input file, evaluates it, and executes it as a project. The solution build is executed before any project. When building from Visual Studio, none of this happens; MSBuild never sees the solution file. As a consequence, solution build customization (using before.SolutionName.sln.targets and after.SolutionName.sln.targets) only applies to MSBuild.exe or object model driven, not Visual Studio builds.

来源:docs.microsoft.com