Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Core.dll in 4.0 added by default?

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?

like image 277
Niranjan Avatar asked Jan 19 '10 05:01

Niranjan


2 Answers

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.

like image 59
Alex Avatar answered Nov 14 '22 20:11

Alex


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.

like image 38
itowlson Avatar answered Nov 14 '22 22:11

itowlson