10
votes

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.

5
Whenever you're asking a question and saying that there's an error, it really helps to cut and paste the error. This goes for exceptions, compiler errors, build errors...Jon Skeet
BTW, if it builds the two projects individually with no problem, then I wonder if the two projects needed the project references. OTOH, this could be working due to the recent feature that permits MSBUILD to be "smart" about project references. As I've never understood that feature, I can't rule that out; but I recommend you confirm whether all of the project references are required, and whether rebuilding B causes rebuild of C.John Saunders
@blntechie: thanks for the update. I suggest you use Solution Explorer; select each reference, in order, and look at the details in the Properties window. See anything strange, like one being in obj and the others in bin? Also, if no reference paths, then you may not mind looking at your .csproj.user files to make sure there really are none?John Saunders
@John Saunders : Thanks for ur help. 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. Help much appreciated.Updating question also.lakshminb7
How did you solve the problem? I'm experiencing the same ...Ignacio Soler Garcia

5 Answers

8
votes

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.

4
votes

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.

3
votes

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.

1
votes

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.

1
votes

Remove the assembly from GAC(C:\WINDOWS\assembly folder - select your assebly and right click and uninstall).

Because solution keeps reference using guid and if that guid is in GAC, it will keep taking GAC version for compilation.