Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild builds projects with project references correctly but not from solution

Tags:

People also ask

How does MSBuild create solution?

To build a specific target of a specific project in a solution. At the command line, type MSBuild.exe <SolutionName>. sln , where <SolutionName> corresponds to the file name of the solution that contains the target that you want to execute.

What is MSBuild process?

MSBuild then works through the instructions in the project file. It builds each of the projects in the solution, using the project file for each project. It then calls out to other tools, like Web Deploy (MSDeploy.exe) and the VSDBCMD utility to deploy your web content and databases to the target environment.


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.