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.
Figured it out:
<ItemGroup>
<ReferenceToBeRemoved Include="@(Reference)" Condition="$([System.String]::Copy("%(Reference.Filename)").StartsWith('MyDllName'))" />
<Reference Remove="@(ReferenceToBeRemoved)" />
</ItemGroup>
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