如何在vcxproj文件中具有条件项目引用

时间:2018-02-09 00:33:01

标签: msbuild vcxproj

我有一个VisualC ++项目作为vcxproj,我需要有条件地包含一个ProjectDependency元素。

我尝试了几种不同的方式,似乎没有任何工作。

在我的fubar.vcxproj中,我有以下内容:

<ItemGroup Condition="'$(BuildRaster)'=='True'">
    <ProjectReference Include="Raster.vcxproj" Condition="'$(BuildRaster)'=='True'">
      <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
      <Private>false</Private>
      <CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
      <LinkLibraryDependencies>true</LinkLibraryDependencies>
      <UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
    </ProjectReference>
</ItemGroup>

在我使用的收集器.proj文件中,我有这个

<ItemGroup>
    <FUBARProject Include="$(Proj_Root)\fubar.vcxproj"/>
</ItemGroup>
<Target Name="BuildWithRaster">
    <MSBuild Projects="@(FUBARProject)" Properties="ExportIncludes=true;Constants=IncludeRaster;BuildRaster=True"/>
</Target>
<Target Name="BuildWithoutRaster">
    <MSBuild Projects="@(FUBARProject)" Properties="ExportIncludes=true;Constants=ExcludeRaster;BuildRaster=False"/>
</Target>

实际上有超过一百个依赖项目,所以这只是一个已删除版本的片段。条件ProjectReference似乎适用于csproj但不适用于vcxproj。我已尝试将条件放在ProjectReference上,也放在ItemGroup元素上;两者都没有区别。

1 个答案:

答案 0 :(得分:0)

我发现了我的问题,条件子句在vcxproj文件中有效。实际上我有一个不同的依赖项带来了我不知道的同一个项目,直到我在构建中打开详细程度。