Skip to content

MSBuild problem: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

Problem:

I tried to build a .net(c#) solution with MSBuild, and got the following error:

The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

Even with a valid using to System.Linq.

The problem seems to be Visual Studio. It seems Visual Studio implicit adds a reference to System.Core, whereas MSBuild does not.

The screenshot shows a small solution, which should be built by MSBuild.

LinqMsbuild1

Buildscript used(master.proj):

<?xml version="1.0" encoding="utf-8"?>

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies> <TargetType>Rebuild</TargetType> <ConfigurationType>Debug</ConfigurationType> </PropertyGroup> <Target Name="CompileTest" > <MSBuild Targets="$(TargetType)" Properties="Configuration=$(ConfigurationType)" Projects= "D:\project\ConsoleApplication3\ConsoleApplication3.sln" /> </Target> </Project>

#Batch to start the build
SET MSBUILD="C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe"
SET LogDll="c:\windows\Microsoft.Net\Framework\v2.0.50727\Microsoft.Build.Engine.Dll"
%MSBUILD% master.proj /tv:3.5  /target:CompileTest /l:FileLogger,Microsoft.Build.Engine;logfile=MyLog.log;verbosity=q;encoding=utf-8 /P:NOWARN=
pause

Building this, the following error is shown from MSBuild:

MSBuildError2

Solution:

Add via notepad(++) a reference to System.Core directly to the csproj/vbproj file:

MSBuildError3

After that, build with MSBuild works fine.

If anyone has a better solution for this problem, please leave a comment.

 

cheers

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

Nyanna on :

Pin my tail and call me a donkey, that really hleepd.

Kirit on :

Awesome...it worked...thanks so much

Sergio on :

Thanks a lot!!!

tuma on :

Working fine! Thanks a lot

Add Comment

You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Markdown format allowed
Form options

Submitted comments will be subject to moderation before being displayed.