简体   繁体   中英

Msbuild fails building website project with an indirect reference to System.Runtime

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM