System.Core.dll in 4.0 added by default?

北慕城南 提交于 2019-12-04 05:06:43

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.

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.

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