第二个SO question的原理可以通过多次调用MsBuild来调整为顺序构建多个配置/平台。例如:
<Target Name="AfterBuild" Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<MSBuild Projects="$(MySolution)" Properties="Configuration=Release;Platform=x86"/>
<MSBuild Projects="$(MySolution)" Properties="Configuration=Debug;Platform=x64"/>
<MSBuild Projects="$(MySolution)" Properties="Configuration=Release;Platform=x64"/>
</Target>
这可以通过使用项目批处理、删除条件并自动确定调用哪个配置然后只构建其他配置等来清理,但这有点超出了这里的范围。
我并不认为在 AfterBuild 目标中执行此操作是最好的方法,因为这样您就需要调整一个“正常”项目以触发其他所有项目的构建。另一种方法是将MakeFile Project 添加到您的解决方案中,设置它的依赖项,使其在构建顺序中排在最后(至少如果这是您需要的),并将其设置为命令行以类似于以下方式调用 msbuild如上所述。您甚至可以将所有逻辑保存在同一个项目文件中:将“构建命令行”设置为
msbuild $(MsBuildThisFile) /t:CustomBuild /p:Configuration=$(Configuration);Platform=$(Platform)
因此,构建项目将“递归”并使其再次调用自身,并使用与 VS 调用相同的属性,但执行 CustomBuild 目标,然后您可以在其中构建其他项目/解决方案以品尝。
重新编辑:更新
您快到了,但您必须转到配置管理器并确保配置正确设置开始。从一开始:
- 创建新解决方案,添加 3 个项目
- 右击解决方案,选择配置管理器
- 在活动解决方案配置组合框中选择新建
-
name 输入 CORE_DEBUG,在 Copy settings from 下选择 DEBUG,并确保像 一样选中 Create new project configurations
- 重复其他配置
- 例如,对于 EXTENDED_RELEASE,它现在应该看起来像
- 您可能已经完成了大部分工作,但不知何故 Debug 被分配给 EXTENDED_RELEASE,所以这是您应该修复的一件事;您可以通过手动编辑解决方案来做到这一点,但您不必删除行,而是必须编辑它们以使其正确,否则 VS 只需再次添加它们,正如您所注意到的那样
现在在文本编辑器中打开第一个项目,在已插入 AfterBuild 但已注释掉的文件末尾附近,添加
<ItemGroup>
<Configurations Condition="'$(Configuration)'=='Debug'" Include="CORE_DEBUG;EXTENDED_DEBUG" />
<Configurations Condition="'$(Configuration)'=='Release'" Include="CORE_RELEASE;EXTENDED_RELEASE" />
<Projects Include="$(SolutionDir)WindowsFormsApplication1.csproj;$(SolutionDir)WindowsFormsApplication2.csproj;$(SolutionDir)WindowsFormsApplication3.csproj" />
</ItemGroup>
<Target Name="AfterBuild" Condition="'@(Configurations)' != ''">
<Message Text="Projects=@(Projects) Configuration=%(Configurations.Identity)" />
<MSBuild Projects="@(Projects)" Targets="Build" Properties="Configuration=%(Configurations.Identity)" />
</Target>
您可能需要调整项目的路径。这将为 Debug 构建构建 CORE_DEBUG 和 EXTENDED_DEBUG,对于 Release 构建也是如此。当 Configurations ItemGroup 为空时,即不构建 Debug 或 Release 时,会跳过 AfterBuild。
重新编辑:makefile
您可以为 makefile 命令行指定多个命令。单击“构建命令行”框旁边的箭头并选择“”为确保一切正常,必须将配置管理器设置为仅构建用于调试/发布的 makefile 项目,例如:
makefile 项目的命令行看起来像
或者,我自己更喜欢这个,您创建一个与上述内容相同的 msbuild 文件:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Configurations Condition="'$(Configuration)'=='Debug'" Include="CORE_DEBUG;EXTENDED_DEBUG" />
<Configurations Condition="'$(Configuration)'=='Release'" Include="CORE_RELEASE;EXTENDED_RELEASE" />
<Projects Include="$(SolutionDir)WindowsFormsApplication1.csproj;$(SolutionDir)WindowsFormsApplication2.csproj;$(SolutionDir)WindowsFormsApplication3.csproj" />
</ItemGroup>
<Target Name="Build" Condition="'@(Configurations)' != ''">
<Message Text="Projects=@(Projects) Configuration=%(Configurations.Identity)" />
<MSBuild Projects="@(Projects)" Targets="Build" Properties="Configuration=%(Configurations.Identity)" />
</Target>
</Project>
然后您的 makefile 命令会像调用该文件一样
msbuild /path/to/msbuildfile /t:Build /p:Configuration=Debug;SolutionDir=$(SolutionDir)