【问题标题】:Avoid "The OutputPath property is not set for project" by specifying default build config通过指定默认构建配置来避免“未为项目设置 OutputPath 属性”
【发布时间】:2014-04-13 19:03:49
【问题描述】:

我有类似以下的情况:

一个包含两个项目的解决方案,AB,其中 A 引用 B。除了标准的构建配置DebugRelease,我想添加第三个Staging,它可以让我只对项目A 进行一些配置转换。 Staging 构建配置对 B 没有影响,所以我没有将它添加到项目中。

使用解决方案配置管理器,很容易设置此方案...当活动配置为 Staging 时,A 将使用 StagingB将使用Debug。解决方案按预期构建。但是,运行

msbuild A.csproj /p:Configuration=Staging

由于 B 没有 Staging 构建配置,因此会因 The OutputPath property is not set for project B 而失败。

我的问题是在通过msbuild 构建项目时是否有一种简单的方法可以避免这种情况

Staging 配置添加到B 是可行的,但只将构建配置添加到它们影响的项目中似乎更简洁,其余部分则不用管。在包含许多项目的解决方案中,确保每个项目都具有所有可能的构建配置并不理想(尽管也不是很糟糕)。

【问题讨论】:

    标签: .net visual-studio msbuild


    【解决方案1】:

    在 A.csproj 文件中添加以下行

      <ItemGroup>
        <ConfigList Condition=" '@(ConfigList)' == '' and $(Config) != '' " Include="$(Config.Split('+'))" />
        <!-- parse all requested configurations into a list -->
        <ConfigList Condition=" '@(ConfigList)' == '' " Include="Debug" />
        <!-- if no configurations were specified, default to Debug -->
      </ItemGroup>
    

    并在 A.csproj 中为引用的项目添加一个目标

      <Target Name="Build">
        <MSBuild Projects="$(MSBuildProjectDirectory)\..\B\B.csproj" Properties="Configuration=%(ConfigList.Identity);OutputPath=$(MSBuildProjectDirectory)\bin\%(ConfigList.Identity)" Targets="Build" />
      </Target>
    

    当您使用 /p:Configuration=Staging 构建项目 A 时,引用项目的目标将传递配置并创建所需的输出目录。

    看看这个post,它清楚地描述了你想要做什么。

    【讨论】:

      猜你喜欢
      • 2012-08-26
      • 2014-01-20
      • 2018-04-29
      • 2012-02-23
      • 1970-01-01
      • 1970-01-01
      • 2019-10-26
      • 2016-02-18
      相关资源
      最近更新 更多