rlucas.net: The Next Generation Rotating Header Image

Force a reference to System.Core in Visual Studio 2010

There are reasons why you might need to add a reference to “System.Core” to your Microsoft Visual Studio project. (For example, if you wish to compile/build both inside the IDE and from the command-line with MSBuild.exe.)

However, if you try to do this through the IDE, it will barf at you: “A reference to ‘System.Core’ could not be added. This component is already automatically referenced by the build system.”

Alas, that’s a big fucking lie. It’s referenced by the IDE when it invokes the build system, but not by MSBuild itself. So sometimes, you indeed must add such a reference, but you can’t do it from IDE-land. So close VS2010 and fire up vim. Add a line to the .csproj file in question, telling it to:

<Reference Include="System.Core" />

Hat tip to Ashby at StackOverflow:
http://stackoverflow.com/questions/1302488/the-type-or-namespace-name-linq-does-not-exist-in-the-namespace-system-data/4331322#4331322

I got to this point when recompiling something for .NET 3.5 that had originally been coded/built for .NET 4.0; it wouldn’t import the LINQ namespace without being told to import System.Linq, but then couldn’t find it without the System.Core reference being made explicit. Arrgh.

3 Comments

  1. Patrick says:

    Thank you so much for posting this. Trying to find out why our build server was rejecting my new VS2010 application was driving me insane.

  2. Antonio says:

    Same as Patrick. Thank you.

  3. Michael says:

    Thanks a bunch. I had the same Problem also. Luckily our build server puts out a lot of useful error logs, and I was able to pinpoint the problem quickly.

Leave a Reply

Your email address will not be published. Required fields are marked *