Remove MSBuild DLL reference regardless of version (by wildcard) in VS 2015

陌路散爱 提交于 2019-12-08 01:24:35

问题


In a C# project I have a DLL reference that I want to remove before the build (to be replaced with another - this an attempted solution to Easily override NuGet DLL in development (VS 2015)). The following target seems to work:

  <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>

The problem with this is that I need to specify the exact version of the DLL to remove, which can change. I want to remove it regardless of version. I tried a wildcard

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

... but that didn't seem to match anything, because I got error CS1704: An assembly with the same simple name 'My' has already been imported.


回答1:


Figured it out:

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



回答2:


use:

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


来源:https://stackoverflow.com/questions/33367161/remove-msbuild-dll-reference-regardless-of-version-by-wildcard-in-vs-2015

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!