如何使用MSBuild为每个项目的每个构建配置提供不同的OutputPath? [英] How to give a different OutputPath per project per build configuration with MSBuild?

查看:139
本文介绍了如何使用MSBuild为每个项目的每个构建配置提供不同的OutputPath?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

必须使用一个或多个配置(调试/发布/...)来构建多个项目.

Multiple projects have to be build with one ore more configurations (debug/release/...).

需要将构建的输出复制到文件夹(BuildOutputPath). 有一个默认的BuildOutputFolder,但是对于某些项目,您可以指示输出需要放置在额外的子文件夹中.

The output of the build needs to be copied to a folder (BuildOutputPath). There is a default BuildOutputFolder, but for some project you can indicate that the output needs to be put in a extra child folder.

例如:

配置为: -调试 -释放

Configuration are: - debug - release

这些项目是:

  • Project1(BuildOutputFolder)
  • Project2(BuildOutputFolder)
  • Project3(BuildOutputFolder \ Child)

最终结果应如下所示:

\\BuildOutput\
     debug\
         project1.dll
         project2.dll
         Child\
               Project3.dll
     release\
         project1.dll
         project2.dll
         Child\
              Project3.dll

我已经获得了如此高的atm,但无法弄清楚如何覆盖每个项目的OutputPath.

I got this far atm, but can't figure out how to override the OutputPath per project.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="Build" >
  <ItemGroup>
    <ConfigList Include="Debug" />
    <ConfigList Include="Release" />
   </ItemGroup>  

  <PropertyGroup>
    <BuildOutputPath>$(MSBuildProjectDirectory)\BuildOutput\</BuildOutputPath>
  </PropertyGroup>

  <ItemGroup>
    <Projects Include="project1.csproj" />
    <Projects Include="project2.csproj" />
    <Projects Include="project3.csproj" />
  </ItemGroup>

  <Target Name="Build">
    <MSBuild Projects="@(Projects)"
             BuildInParallel="true"
             Properties="Configuration=%(ConfigList.Identity);OutputPath=$(BuildOutputPath)%(ConfigList.Identity)" />

  </Target>
</Project>

您将如何在MSBuild项目文件中完成此操作?

How would you accomplish this in a MSBuild project file ?

推荐答案

您尝试在两个不同的上下文中递归调用任务. 2个配置和3个项目需要对构建任务的6个调用.您需要以如下方式对项目进行布局:对于ConfigList中的每个项目,调用都会乘以Projects中的每个项目.

Your'e attempting to call a task recursively in two different contexts. 2 configurations and 3 projects requires 6 calls to the build task. You need to layout the project in such a way that for each item in ConfigList a call is made multiplied by each item in Projects.

还使用 ItemDefinitionGroup 进行设置默认共享属性:

Also use ItemDefinitionGroup to set default shared properties:

  <ItemGroup>
    <ConfigList Include="Debug" />
    <ConfigList Include="Release" />
  </ItemGroup>

   <ItemDefinitionGroup>
    <Projects>
      <BuildOutputPath>$(MSBuildProjectDirectory)\BuildOutput\</BuildOutputPath>
    </Projects>
  </ItemDefinitionGroup>

  <ItemGroup>
    <Projects Include="project1.csproj" />
    <Projects Include="project2.csproj" />
    <Projects Include="project3.csproj" >
      <Subfolder>Child</Subfolder>
    </Projects>
  </ItemGroup>

  <Target Name="Build">

    <MSBuild Projects="$(MSBuildProjectFullPath)"
             Targets="_BuildSingleConfiguration"
             Properties="Configuration=%(ConfigList.Identity)" />

  </Target>

  <Target Name="_BuildSingleConfiguration">

    <MSBuild Projects="@(Projects)"
             BuildInParallel="true"
             Properties="Configuration=$(Configuration);OutputPath=%(Projects.BuildOutputPath)$(Configuration)\%(Projects.Subfolder)" />
  </Target>

</Project>

这篇关于如何使用MSBuild为每个项目的每个构建配置提供不同的OutputPath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆