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 开发者_StackOverflow社区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?
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 bec:\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.
精彩评论