项目 - 条件多条线

时间:2016-11-10 13:57:16

标签: visual-studio msbuild

我有一个项目需要不同版本的几个DLL,具体取决于发布配置。

通常我会这样做:

.then()

这适用于其他Build-configuration:

<Reference Condition=" '$(Configuration)|$(Platform)' == 'V16Release|AnyCPU' " Include="Microsoft.SharePoint.Client.Runtime, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
  <HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.5626.1200\lib\net45\Microsoft.SharePoint.Client.Runtime.dll</HintPath>
  <Private>True</Private>
</Reference>
<Reference Condition=" '$(Configuration)|$(Platform)' == 'V16Release|AnyCPU' " Include="Microsoft.SharePoint.Client.Runtime.Windows, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
  <HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.5626.1200\lib\net45\Microsoft.SharePoint.Client.Runtime.Windows.dll</HintPath>
  <Private>True</Private>
</Reference>

如您所见,根据发行版配置,会加载不同的DLL。

虽然这有效,但不仅仅是两个包。那么有没有办法将我的条件分组:

<Reference Condition=" '$(Configuration)|$(Platform)' == 'V15Release|AnyCPU' " Include="Microsoft.SharePoint.Client.Runtime, Version=15.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
  <HintPath>..\packages\Microsoft.SharePointOnline.CSOM.15.1.1626.1200\lib\net45\Microsoft.SharePoint.Client.Runtime.dll</HintPath>
  <Private>True</Private>
</Reference>
<Reference Condition=" '$(Configuration)|$(Platform)' == 'V15Release|AnyCPU' " Include="Microsoft.SharePoint.Client.Runtime.Windows, Version=15.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
  <HintPath>..\packages\Microsoft.SharePointOnline.CSOM.15.1.1626.1200\lib\net45\Microsoft.SharePoint.Client.Runtime.Windows.dll</HintPath>
  <Private>True</Private>
</Reference>

所以只是一个简单的&#34; <Group Condition=" '$(Configuration)|$(Platform)' == 'V15Release|AnyCPU' "> <Reference.... /> <Reference.... /> <Reference.... /> <Reference.... /> </Group> &#34;就像你在代码中写的那样?

1 个答案:

答案 0 :(得分:1)

如果您在编辑器中编辑项目,则会在ItemGroup中看到参考文献,因此您可以为其设置条件,并且具有多个具有不同条件的组:

<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'V15Release|AnyCPU' ">
  <Reference.... />
  <Reference.... />
  <Reference.... />
  <Reference.... />
</ItemGroup >

<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'V16Release|AnyCPU' ">
  <Reference.... />
  <Reference.... />
  <Reference.... />
  <Reference.... />
</ItemGroup >