System.Core.dll in 4.0 added by default?

大兔子大兔子 提交于 2019-12-05 23:10:21

问题


I was playing around with VS2010 beta2. I noticed that if I try to add System.Core.dll to a project which does not already have a reference to that, in VS2010, it complains saying I cannot add that assembly as it is already referenced by the project system. Any idea why they are doing that in VS2010/4.0? Is it because they have forwarded few types to mscorlib from System.Core?


回答1:


Not an answer for "why they are doing that", but could be helpful.

This is how I see the chain of actions that lead to implicit referencing System.Core.dll:

  • You make a project in Visual Studio 2010. It generates .csproj with ToolsVersion=4.0. Suppose it will use MSBuild from .NET 4.
  • Your .csproj imports Microsoft.CSharp.targets from $(MSBuildBinPath). I guess it will be c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets
  • Microsoft.CSharp.targets imports Microsoft.Common.targets
  • In .NET 4, Microsoft.Common.targets imports Microsoft.NETFramework.props
  • In Microsoft.NETFramework.props you can find AdditionalExplicitAssemblyReferences node, which has a semicolon-separated list of assemblies. I found there System.Core.dll and a variable for later replacement.

So, to disable implicit reference of System.Core.dll, you can remove it from the list in AdditionalExplicitAssemblyReferences node in c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.NETFramework.props.

After this, if you use, for example, System.Linq and have no reference to System.Core.dll in your project, you will logically get compile error, just like in Visual Studio 2008.




回答2:


System.Core has been part of the required framework since 3.5, because it includes things like ExtensionAttribute and the LINQ Standard Query Operators. Similarly, if you create a 3.5 project in VS2008, it will automatically add a reference to System.Core for you.



来源:https://stackoverflow.com/questions/2091319/system-core-dll-in-4-0-added-by-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!