.net未从GAC加载的从属程序集的从属程序集

时间:2018-11-21 11:28:37

标签: c# .net .net-assembly gac

GAC包含system.net.http 2.0.0.0,但是构建过程会抱怨找不到它:

The primary reference "ABC.dll" could not be resolved 
because it has an indirect dependency on the framework assembly 
"System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
which could not be resolved in the currently targeted framework. 
".NETFramework,Version=v4.0". 

ABC.dll和我当前的项目都针对.NET Framework 4

gacutil -l的输出显示两个版本:

enter image description here

System.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL

另外尝试过:
将计算机配置更改为无用

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" />
      <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

不能:
更改.csproj,.net版本或将正确的.dll与应用捆绑在一起。由于abc.dll和system.net.http依赖项已作为GAC的一部分部署到客户端计算机,因此仅允许对我的开发计算机进行更改。

1 个答案:

答案 0 :(得分:0)

解决方案

误解:引用程序集在编译过程中来自GAC。
其实他们没有。

您可以将构建日志的详细程度更改为diagnostic,并查看正在哪里搜索哪些程序集。 (Vs Menu -> Tools -> Options -> Projects and Solutions -> Build & Run -> Verbosity

修复

solution explorer-> right click on project-> properties-> reference paths下,添加包含缺少的程序集的目录。

此外,您可以通过在计算机级别上进行编辑
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\AssemblyFolders.config