删除VS 2015中的MSBuild DLL引用,无论版本如何(通过通配符) [英] Remove MSBuild DLL reference regardless of version (by wildcard) in VS 2015
问题描述
在C#项目中,我有一个DLL引用,我希望在构建之前将其删除(要替换为另一个DLL引用-这是
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>
此问题是我需要指定要删除的DLL的确切版本,该版本可以更改.无论版本如何,我都希望将其删除.我尝试了通配符
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" />
...但是似乎没有任何匹配,因为我得到了error CS1704: An assembly with the same simple name 'My' has already been imported.
... 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.
推荐答案
弄清楚了:
<ItemGroup>
<ReferenceToBeRemoved Include="@(Reference)" Condition="$([System.String]::Copy("%(Reference.Filename)").StartsWith('MyDllName'))" />
<Reference Remove="@(ReferenceToBeRemoved)" />
</ItemGroup>
这篇关于删除VS 2015中的MSBuild DLL引用,无论版本如何(通过通配符)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!