Dependency on the framework assembly “System.Runtime, Version=4.0.10.0,” which could not be resolved in the currently targeted framework

对着背影说爱祢 提交于 2020-01-02 02:40:28

问题


TFS 2013 - Build: ASP.Net 4.5.1 website I get this error:

warning MSB3268: The primary reference "C:\Builds\2\MyProj\Web1_Main\bin\MyProj1.dll"
 could not be resolved because it has an indirect dependency on the framework assembly 
"System.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which
 could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.5.1". To resolve this problem, either remove the reference 
"C:\Builds\2\MyProj\Web1_Main\bin\MyProj1.dll" or retarget your application to a framework 
version which contains "System.Runtime, Version=4.0.10.0, Culture=neutral, 
PublicKeyToken=b03f5f7f11d50a3a".

All projects and site was 4.0 initially using Unity 1.0.0.0. I upgraded it to 4.5.2. Also the MyProj1 in the error above is referencing Unity and I upgraded it to 3.5.1 as well.

Read this: https://unity.codeplex.com/workitem/12756 The build server already have the updated 4.5.2 pointed in the workaround.

So I downgraded to 4.5.1 but still getting the error.

  • Solution builds fine locally via Visual studio 2013.

  • The stand alone class libraries project build in TFS fine but when MyProj is added as a reference to my Website, that's when it fails.

Any ideas?

Do I need any web.config changes other than TragetFramework settign while upgrading?


回答1:


Actually sorry I don't think "assemblyBinding" would help. It seems like a known bug. It has not been resolved. Using Unity 3.5 you can target .NET 4.5.1 but not 4.5.2. So one option would be to re-target to .NET 4.5.1 and see if the problem goes away, if that's an option.

p.s. Also you can try .NET Framework 4.5.2 Developer Pack. But some have mentioned it did not work.




回答2:


I had to upgrade my Unity to 3.5 due to my project's dependency on some other project and this error came again. This time, finally got it fixed.

This one helped me: http://devsilos.blogspot.com/2014/10/msb3268-while-targeting-aspnet-web-site.html

Solution I copied all the files that build was complaining about from:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.2\Facades

To

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.2

Here's the explanation from the link above in case it goes down for any reason in future:

A deeper inspection revealed the following interesting fact: aspnet_compiler for some reason does not take into account the .dll-s that reside under the Facade directory of 4.5 assemblies (C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\Facades). It looks only under C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5

As a result the whole thing failed since both System.Threading.Tasks and System.Runtime .dll-s were under the Facades directory and not inside the v4.5.

Now the solutions:

  • Just simply copy the missing .dll-s from Facade to the v4.5 directory.
  • Set the TargetFrameworkMoniker to 4.5.1 in the .sln file. The exact syntax is as follows: TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.5.1".

What happens in this case is that the aspnet_compiler does not recognize the exact version of the required framework and tries to use the GAC wherever it can. If 4.5 is the highest version installed on the build machine I believe it should work.




回答3:


We recently ran into a similar problem with a site that was upgraded to target .NET 4.5, and initially followed the solution in gbs's answer.

In our case, we had several warnings following this pattern:

<project name>.metaproj : warning MSB3268: The primary reference "<project reference>.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=4.0.0.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 "<project reference>.dll" or retarget your application to a framework version which contains "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

We then discovered that if you create a new web site targeting 4.5.x (File > New > Web Site...) and select the ASP.NET Empty Web Site template, the package Microsoft.Net.Compilers is included. Adding this package to our site resolved the issue without the need to touch the reference assemblies.

Of the original two solutions, copying the files caused the build to succeed but presented maintenance concerns, and changing the TargetFrameworkMoniker (to 4.5.3 rather than 4.5.1) produced a different build error and was a brittle solution.



来源:https://stackoverflow.com/questions/26918631/dependency-on-the-framework-assembly-system-runtime-version-4-0-10-0-which-c

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