无论VS 2015中的版本(通配符)如何,都删除MSBuild DLL引用

时间:2015-10-27 11:45:39

标签: c# msbuild visual-studio-2015 msbuild-4.0

在C#项目中,我有一个我想在构建之前删除的DLL引用(要替换为另一个 - 这是Easily override NuGet DLL in development (VS 2015)的尝试解决方案)。以下目标似乎有效:

  <Target Name="BeforeBuild">
    <ItemGroup Condition="Exists('..\..\..\Build\My.dll')">
      <Reference Remove="My, Version=1.2.3.4, Culture=neutral, processorArchitecture=MSIL" />
      <Reference Include="My, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
        <SpecificVersion>False</SpecificVersion>
        <HintPath>..\..\..\Build\My.dll</HintPath>
      </Reference>
    </ItemGroup>
  </Target>

这个问题是我需要指定要删除的DLL的确切版本,这可能会改变。无论版本如何,我想删除它。我试过一个通配符

      <Reference Remove="My, Version=*, Culture=neutral, processorArchitecture=MSIL" />

...但似乎没有任何匹配,因为我得到了error CS1704: An assembly with the same simple name 'My' has already been imported.

2 个答案:

答案 0 :(得分:1)

想出来:

<ItemGroup>
  <ReferenceToBeRemoved Include="@(Reference)" Condition="$([System.String]::Copy(&quot;%(Reference.Filename)&quot;).StartsWith('MyDllName'))" />
  <Reference Remove="@(ReferenceToBeRemoved)" />
</ItemGroup>

答案 1 :(得分:0)

使用:

<Reference Remove="My, Version=1.2.3.4, Culture=neutral, processorArchitecture=MSIL" >
    <SpecificVersion>False</SpecificVersion>
</ Reference>