Monday, October 27, 2014

MSB3268 while targeting ASP.NET web site project to framework 4.5

Just spent 2 days with trying to understand why on Earth my ASP.NET web site project stopped compiling when I re-targeted it to framework 4.5.

My dependent projects were all re-compiled under framework 4.5 without any issue.

Visual Studio 2012 compiled the web site without any issue either.

While the build server, working under Jenkins had its MSBuild job failing with MSB3268 warnings saying that the System.Threading.Tasks and System.Runtime assemblies could not be found under the framework version of "v4.5".

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:

  1. Just simply copy the missing .dll-s from Facade to the v4.5 directory.
  2. 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.

Very tiring.

4 comments:

  1. Adding the Microsoft.Net.Compilers package to the project solved this issue for us.

    This package is included in the ASP.NET Empty Web Site template for sites targeting 4.5.x, but is not added automatically to sites when the target framework is changed to 4.5.x from a previous version.

    ReplyDelete
  2. I've tried adding the Microsoft.Net.Compilers package but it doesn't help. My site targets 4.5.2 and builds locally, but using MSBuild 14 on a different server fails with this error message.

    ReplyDelete
  3. Oh, the fun, I want to stress the fact you need to pay attention to copy all the dlls about the build complains. I forgot one and I thought this wasn't the solution.

    ReplyDelete
  4. Just spent some painful 4 hours on this... Jeez...

    ReplyDelete