.net – MSBuild builds projects with project references correctly but not from solution

msbuildnet

When i build a A.sln which includes 2 projects B.csproj and C.csproj which has internal project references it throws reference errors in MSBuild. But when i build B.csproj and C.csproj seperately in MSBuild it don't throw errors. And also building A.sln in VS IDE also don't throw errors.I'm using .NET 2.0 framework. Please find below the scripts used to build the sln and projs.

MSBuild "<path>/A.sln" /p:Configuration=Release /p:StartupObject="" /p:WarningLevel=4 /p:Optimize=true /t:rebuild /l:Filelogger,Microsoft.Build.Engine;logfile=F:\A.sln.log /verbosity:normal

MSBuild "<path>/B.csproj" /p:Configuration=Release /p:StartupObject="" /p:WarningLevel=4 /p:Optimize=true /t:rebuild /l:Filelogger,Microsoft.Build.Engine;logfile=F:\B.csproj.log /verbosity:normal 

MSBuild "<path>/C.csproj" /p:Configuration=Release /p:StartupObject="" /p:WarningLevel=4 /p:Optimize=true /t:rebuild /l:Filelogger,Microsoft.Build.Engine;logfile=F:\C.csproj.log /verbosity:normal 

Edit:

All the errors thrown are from code for missing refernces(all are project references). I get only three type of errors like given below.

error CS0012: The type 'X' is defined
in an assembly that is not referenced.
You must add a reference to assembly
'Y, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=aad4cbe5d7c27078'.

error CS0234: The type or namespace
name 'X' does not exist in the
namespace 'Y' (are you missing an
assembly reference?)

error CS0246: The type or namespace
name 'X' could not be found (are you
missing a using directive or an
assembly reference?)

I cleared all previously built dlls from build paths before building from both IDE and MSBuild. But IDE just works fine and don't show a reference missing indicator in "Refrences" section for the project.

No reference paths added manually in IDE.

Another Update:

I just noticed that when i open both the projects from the solution, references are correctly pointing in IDE. But when i open the projects seperately in IDE, the missing references i mentioned occuring in MSBuild creeps up. Very wierd.

So to summarize,

Buiilding .proj in MSBuild – Good

Buiilding .proj in IDE – Error

Buiilding .sln in MSBuild – Error

Buiilding .sln in IDE – Good

Looks very wierd for me. Help much much appreciated.

Best Answer

MSBuild and VS both use project references and project dependencies to choose the solution build order. Beyond that, it's undefined - and typically different between the two. Check both of these are correct. Project dependencies are set in the properties of your solution. If that doesn't work, double check the GUIDs in the project references in your projects match the ones in the solution. Sometimes recreating the solution can fix them.