5

I am running into a dependency issue with MSBuild. I added a NuGet package for Microsoft.Tpl.Dataflow to a project in my solution. This is causing a build failure for a website project in the solution which references the first project. There seems to be an issue with getting the correct runtime version.

This is one of the many errors I get when building the solution with MSBuild.

C:\src\MyWebsite.metaproj : warning MSB3268: The primary reference "C:\src\projects\ReferencedProject\bin\Debug\ReferencedProject.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 "C:\src\projects\ReferencedProject\bin\Debug\ReferencedProject.dll" or retarget your application to a framework version which contains "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

The confusing thing to be is that the solution builds fine in Visual Studio. Also, all the other projects in the solution build—it's only the website projects that are failing.

I have tried

  • Changing the target framework for the website to 4.0 (it's currently 4.5).
  • Adding an assembly reference to System.Runtime.dll version 4.0.0.0

I still can't get it to build. How can I fix this?

Kris Harper
  • 5,672
  • 8
  • 51
  • 96

1 Answers1

5

Turns out aspnet_compiler.exe (which is called by msbuild) does not look for libraries in the Facade directory at

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

and as such, the website project in the solution would not compile.

I found this out from this blog post. As mentioned there, to fix the problem I copied the DLLs from the Facade directory into the v4.5 directory and everything works.

To be honest this is a less than ideal solution.

Kris Harper
  • 5,672
  • 8
  • 51
  • 96
  • Thanks for sharing this. – frattaro Mar 17 '17 at 15:20
  • This also happened to us in .net 4.7. I'd like to add this only happened to us when using msbuild command line on a build server, and not in visual studio. Although this solution does also work, since 4.7 also has the Facades directory, there has got to be a better way than by copying the system files, which would have to be done on every build server. – Michael Adamission Oct 21 '17 at 21:31
  • If someone wants to dig into this more to try to do it the right way, or verify to report it to Microsoft, I 'think' there is an underlying msbuild paramater called TargetFrameworkDirectories that is missing that path. As for how to get it in there using aspnet_compiler, I'm not sure because I don't know if you can pass parameters to it. As for now I'm going to use the less than ideal solution of copying the files. – Michael Adamission Oct 21 '17 at 22:48
  • 2
    @MichaelAdamission: I *think* that worked for me. In my pipeline, I passed: `msbuildArgs: '/p:TargetFrameworkDirectories="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\Facades;$(TargetFrameworkDirectories)""'` – Sören Kuklau Jul 11 '22 at 15:10
  • It would appear that it is still a problem in the 4.8 framework. I could build and publish from within Visual Studio 2019 on my machine and the build machine but when building from within TFS msbuild the error continues to occur. Setting the MSBuildArgs to the v4.8 directory did not fix the error. The dirty solution of copying the files from Facades to it's parent DID work. This is bloody awful. – kgw Dec 28 '22 at 22:29