tags:

views:

2581

answers:

4

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.

+1  A: 

As Jon Skeet mentioned, an error message would be helpful to knowing what the problem is. Without any details, though, if it builds in the IDE but doesn't build in MSBuild, it sounds like you might have DLLs you are referencing in your projects that are not available in the path where you are building the solution. Perhaps you manually were copying them to somewhere the IDE could find them, or you had reference paths set up in your IDE to look in a certain folder.

Just something to check while you're getting those other details onto the question.

EDIT: Now that there are some details, it could be an order of build problem. Is there a project reference in project B to project C? If so, you may just need to change the order to build project C before project B.

Jay S
In my case Proj C has reference to Proj B. And Proj B builds before Proj C.
blntechie
+2  A: 

Some things to consider: building a solution in the IDE is not the same as running MSBUILD on the .sln file. You might try using devenv.exe /rebuild A.sln instead. The IDE plays several games to allow a .sln file to build, including creating an "equivalent" MSBUILD-style project.

Also, the IDE does not directly just spawn off MSBUILD commands. There is interaction between the two in order to improve performance. For instance, the CSC tasks in the project are probably being executed inside the IDE, instead of as separate command-line builds, as MSBUILD would have spawned them.

You should also consider getting Process Monitor from http://technet.microsoft.com/sysinternals/ in order to watch which files are being accessed.

John Saunders
+2  A: 

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.

dan moseley
A: 

For me, when I've had this (or a similar) problem, manually checking (and fixing) the guids line up fixes my problem. It's annoying to trace down guids between .sln and .csproj files, but it works.

I usually drop the project reference and re-add it, and that fixes the problem (once I've found the offending mismatched guids). Maybe I should just try that first. It's easier.

McKay