鉴于所有其他答案,可以在 .Net 附带的 Targets 文件中找到 MSBuild 在 VS 或 MSBuild 执行构建时所做的事情。这些可以在系统的 FrameWork 目录中找到。就我而言:
C:\Windows\Microsoft.NET\Framework64\v3.5
包含Microsoft.Common.targets 等。此文件包含以下代码段:
<!--
============================================================
Build
The main build entry point.
============================================================
-->
<PropertyGroup>
<BuildDependsOn>
BeforeBuild;
CoreBuild;
AfterBuild
</BuildDependsOn>
</PropertyGroup>
<Target
Name="Build"
Condition=" '$(_InvalidConfigurationWarning)' != 'true' "
DependsOnTargets="$(BuildDependsOn)"
Outputs="$(TargetPath)"/>
这意味着重新定义这个 Target 可以让 MSBuild 成为一个 VS 做任何你想做的事情。上述文件的顶部包含一条重要信息:
Microsoft.Common.targets
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.
This file defines the steps in the standard build process for .NET projects. It
contains all the steps that are common among the different .NET languages, such as
Visual Basic, C#, and Visual J#.
我的建议是阅读有关 MSBuild 及其构建文件语法的所有信息,并尝试在您的项目中重新定义构建目标。我的印象是,在阅读了 MSBuild 之后,您可能会找到一种更简单的方法来满足您的要求。您可以在this so question 的答案之一中找到像这样重新定义目标的示例。
编辑:
如何重新定义目标?
重新定义本质上是在定义它之后定义相同的目标。因此,例如在您的 .*proj 文件中,在 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 行之后定义一个 Build Task,该行导入在这种情况下构建 C# 项目所需的所有目标。一个例子可以是
<Target
Name="Build"
Condition=" '$(_InvalidConfigurationWarning)' != 'true' "
DependsOnTargets="BeforeBuild"
Outputs="$(TargetPath)">
<Exec Command="nmake" />
</Target>