我使用Google URL Shortener API有一个WPF(.NET 4)项目,我已经通过nugget https://www.nuget.org/packages/google.apis.apis.apis..urlshortener.v1/1.7.0.25-beta
该应用程序在Visual Studio中运行良好,但一旦发布就会引发异常无法加载文件或汇编系统。threading.tasks,版本= 2.5.19.0此和所有其他组件都存在于安装文件夹中,并且随着应用程序发布。我已经搜索了互联网,人们建议在app.config中手动绑定依赖关系库,它仍然无法正常工作,因为我的所有依赖库已在app.config中提到,下面是我的app.config看起来
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.2.13.0" newVersion="1.2.13.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Threading.Tasks.Extensions.Desktop" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.0.165.0" newVersion="1.0.165.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
您可能会从Microsoft BCL团队博客开始,并通过删除错误的条目来清理app.config
,
http://blogs.msdn.com/b/bclteam/p/asynctargetingpackkb.aspx(Archive)
问题6
症状
将Nuget软件包添加到另一个项目消费的项目时带有不同目标框架的项目您可能会看到警告类似于以下内容:
The primary reference "Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.5". To resolve this problem, either remove the reference "Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" or retarget your application to a framework version which contains "System.Runtime, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
The primary reference "Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.5". To resolve this problem, either remove the reference "Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" or retarget your application to a framework version which contains "System.Runtime, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
解决方案
问题是Nuget添加了错误的绑定重定向平台组件。要删除它们,请打开app.config引起警告并删除突出显示的项目条目[
*****
指出]:
<?xmlversion="1.0"encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBindingxmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>******
<assemblyIdentityname="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirectoldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
</dependentAssembly> .
<dependentAssembly>******
<assemblyIdentityname="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirectoldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
评论:
使用.NET Framework 4.0寿命,您应该三思而后行,然后再使用异步定位包。如果此依赖关系来自Nuget软件包,则还应检查Nuget软件包是否具有没有这种依赖性的较新版本。
我在UWP项目(VS2015)中有一个非常相似的问题("无法加载文件或汇编Microsoft.threading.tasks,versy = 1.0.12.0"),我通过从Nuget安装Microsoft.bcl.async软件包
i存在完全相同的问题,但它是由汇编Microsoft.rest.clientruntime引起的。就我而进