为什么带参考汇编的VS2012项目无法自动定位4.0

G. *_*nev 4 reference target-framework visual-studio-2012

在Visual Studio 2012 C#控制台应用程序中,我将".NET Framework Target"从4.5降级到4.0.安装了两个框架的Win 7 Pro.

然后我引用一个程序集,通过警告抱怨以下内容:

The primary reference "System.Threading.Tasks.Dataflow, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" 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.0". To resolve this problem, either remove the reference "System.Threading.Tasks.Dataflow, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" or retarget your application to a framework version which contains "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

如果我在这一点上尝试编译,我会出错,因为引用程序集中的类型和命名空间不可用,就好像根本没有引用程序集一样.

"添加引用"对话框没有任何 System.Runtime选项,但如果我手动选择C:\ Windows\Microsoft.NET\Framework\v4.0.30319 \并引用那里找到的System.Runtime程序集,则警告会消失我能够编译.

问题:

  1. 是这样强制System.Runtime版本是一个潜在的问题(部署).

  2. 如果VS Project属性是seto到目标框架4.0(与定位4.0 SystemRuntime/CLR没有关系),为什么引用的DLL没有选择它以及为什么手动添加对我的项目的引用修复了这个问题?

aKz*_*enT 5

即使该库System.Runtime位于C:\Windows\Microsoft.NET\Framework\v4.0.30319\目录中,它也不是.NET 4.0框架的一部分..NET 4.5是4.0的就地更新,安装在具有相同版本号的同一文件夹中.

这是一个屏幕截图,证明该库在.NET 4.0安装上不存在:

普通4.0安装

您还可以通过浏览到C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework找到所有已安装框架版本的原始程序集的目录来验证这一点.您将找到和子目录的System.Runtime.dll一部分..NETCore\v4.5.NETPortable\v4.5

您可以将库添加到项目的原因是运行时没有在4.0和4.5之间更改,因此Visual Studio不知道甚至不关心您手动添加的库是否由4.5安装.在这种情况下,Visual Studio中的目标只是一个过滤器,可以避免您意外地将4.5程序集添加到以4.0为目标的项目中.

附加信息:

Rick Strahl有一篇关于这个主题的非常好的博客文章,有更详细的分析:

http://www.west-wind.com/weblog/posts/2012/Mar/13/NET-45-is-an-inplace-replacement-for-NET-40