VB.Net-MSBuild配置-选择性地包括要生成的文件



我正在寻找一种方法,根据指定的配置选择性地包含一组第三方DLL。Version1和Version2的引用不需要更改,只需要更改生成中包含的DLL即可。

更具体地说,Version1和Version2都包含相同的DLL,只是不同的版本。例如,他们都有库:

  • Library.Common.dll
  • Library.Orange.dll
  • 库.Red.dll

然后,我的代码引用那些DLL中定义的接口/类/命令。我希望能够在将这些DLL的版本1用作内容和将这些DLL版本2用作内容之间轻松切换。

理想情况下,我可以做一些类似的事情:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release_Version1|AnyCPU'">
    <OutputPath>binRelease_Version1</OutputPath>
    <!-- Looking for the correct way to do the line below -->
    <IncludeItemGroup name="Version1"/>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release_Version2|AnyCPU'">
    <OutputPath>binRelease_Version2</OutputPath>
    <!-- Looking for the correct way to do the line below -->
    <IncludeItemGroup name="Version2"/>
</PropertyGroup>
<ItemGroup Label="Version1">
    <Content Include="libVersion1*.dll" />
</ItemGroup>
<ItemGroup Label="Version2">
    <Content Include="libVersion2*.dll" />
</ItemGroup>

有人对此有什么好建议吗?

根据您的代码,您似乎希望为每个ItemGroup元素添加一个与$(Configuration)的值相关的条件。

<ItemGroup Label="Version1" Condition=" '$(Configuration)' == 'Release_Version1' ">
    <Content Include="libVersion1*.dll" />
</ItemGroup>
<ItemGroup Label="Version2" Condition=" '$(Configuration)' == 'Release_Version2' ">
    <Content Include="libVersion2*.dll" />
</ItemGroup>

最新更新