8

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?

gbs
  • 7,196
  • 5
  • 43
  • 69
  • I think so . Have you looked at the ? – Spock Nov 14 '14 at 01:57
  • @Spock No I haven't. Any suggestion on what needs to be done in there. As the error says and I see that Unity 3.5 needs Runtime 4.0.10.0 but my site is targeted to 4.5.2. In this case how will the setting look like? – gbs Nov 14 '14 at 16:40

3 Answers3

4

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.

gbs
  • 7,196
  • 5
  • 43
  • 69
  • This is unbelievable. I've spent countless hours on this MSBuild problem. I've analyzed dependencies and even THEIR dependencies with ILSpy. I've searched the web and tried a handful of solutions - all to no avail. Still getting an error that something "could not be resolved because it has an indirect dependency on the framework assembly System.Runtime [...] which could not be resolved in the currently targeted framework .NETFramework,Version=v4.8"... and then I've found your solution. "Ridiculous!" I thought, but lacking any better ideas, I tried it... and it worked. Absolutely unbelievable. – pKami Nov 24 '21 at 19:56
2

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.

Spock
  • 7,009
  • 1
  • 41
  • 60
  • Yes that's the bug I mentioned in the question and I had already tried new developer pack and it didn't work. And I already gave up and moved to actually 4.5. – gbs Nov 17 '14 at 22:09
  • Installing the .Net Framework 4.5.2 Developer Pack worked for me. – deadlydog Nov 12 '15 at 16:19
0

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.

Community
  • 1
  • 1
  • I did not try use the second option explicitly. Yes maintenance would be an issue and if a new build server is setup we need to fix that too. I will try out your fix. I found the solution two days ago, wish you had found before me, could have saved me hours :) – gbs Jun 23 '16 at 00:56