我们有一个通过 VisualStudio2017 创建和维护的解决方案,其中我们的.csprojs被放置在虚拟文件夹中,如下所示:
Solution.sln
\- VirtualFolder1
\- Foo.Common.Bar.csproj -> Bar\bin
\- Foo.Common.Ping.csproj -> Ping\bin
\- Foo.Common.Pong.csproj -> Pong\bin
\- VirtualFolder2
\- Foo.Utils.Bar.csproj -> Utils.Bar\bin
\- Foo.Utils.Ping.csproj -> Utils.Ping\bin
\- Foo.Utils.Pong.csproj -> Utils.Pong\bin
正如预期的那样,每个 .csproj 文件都已经包含一个定义输出路径应该在哪里的部分:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>[Bar/bin or Ping/bin etc]</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>[Bar/bin or Ping/bin etc]</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
我们希望将所有.Common .csproj和.Utils .csproj项目整体构建到各自的输出文件夹中,而不必在我们的 msbuild-script(由 JenkinsCI btw 调用)中一一指定。为了实现这一点,我们尝试了:
<ItemGroup>
<ALL_PROJECTS_IN_SOLUTION_EXCEPT_TESTS
Include="$(_codeFolderpath)\**\*.csproj"
/>
</ItemGroup>
<MSBuild
Projects="@(ALL_PROJECTS_IN_SOLUTION_EXCEPT_TESTS)"
Properties="Platform=$(Platform);Configuration=$(Configuration)"
BuildInParallel="true"
/>
然而,这会导致我们所有的 .csproj 出现以下错误:
The OutputPath property is not set for project [...].csproj
这很奇怪,因为 OutputPath 是在我们的 .csproj 文件中定义的(如上所示)。
如果我们指定“输出”属性,那么问题当然会消失,但是我们真正想要的是这些项目将自己输出到它们各自适当的输出目录中(如上所示)。如何实现这一目标?