Can I build multiple configurations of a project within one solution configuration?

隐身守侯 提交于 2019-12-03 12:12:58

Just figured out a way to do what you asked for. Create one msbuild file (I named mine multiple.proj) and add the script below.

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Choose>
    <When Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
      <ItemGroup>
        <ProjectToBuild Include="$(MSBuildProjectName).csproj">
          <Properties>Configuration=Release</Properties>
        </ProjectToBuild>
      </ItemGroup>
    </When>
  </Choose>
  <Target Name="BeforeBuild">
    <Message Text="Building configuration $(Configuration)..." />
  </Target>
  <Target Name="AfterBuild">
    <MSBuild Projects="@(ProjectToBuild)"/>
  </Target>
</Project>

</type>
</this>

Import the script on your projects (csproj or vbproj):

<Import Project="..\multiple.proj" />

This script tells msbuild to build again your project with another configuration as an AfterBuild event. I used Debug/Release to make the example, but you can easily change the script to support other configurations, or make the decision to build again based on other variables.

Be careful because you're running two builds at once, so build errors can be harder to understand.

Hope this helps.

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