3

i have some visual studio projects which depend on other projects, which have different configurations.

example:
Project MyProject (Configuration: Release)
  References:
    Project LibA (Configuration: Release_DontLink)
    Project LibB (Configuration: Release

Building using Visual Studio works correctly as the Configurations to be used for the different projects are stored inside the solution file.

But when i use msbuild to build MyProject, it builds the Release configuration of LibA, which is incorrect. Since both LibA and LibB are used by numerous other Projects, i cant change those configurations, i only have control over MyProject.

Is there any way to build MyProject using MsBuild without changing the LibA and LibB projects?

Possibly related question: Configuration for ProjectReference in MSBuild, however i did not fully understand the answer, and i think it would require me to change LibA/LibB

Community
  • 1
  • 1
smerlin
  • 6,446
  • 3
  • 35
  • 58

2 Answers2

2

On the solution level (i.e: MyProject.sln), open the property pages and set the Release configuration to build Release_DontLink configuration for project LibA. If you don't have control over the sln file, you should be able to create a copy of it (i.e: MyProject.Release.sln).

sln properties

Then build the solution with:

msbuild MyProject.sln /p:Configuration=Release

Alternatively (not even remotely a best practice), after building MyProject build LibA while overriding its OutDir property:

msbuild LibA.csproj /p:Configuration=Release_DontLink;OutDir=..LibA\Release
KMoraz
  • 14,004
  • 3
  • 49
  • 82
  • thats what i am already doing... and thats causing LibA to be build with Release aswell, while it should be build with Release_DontLink – smerlin Jun 25 '12 at 17:36
  • yes, calling msbuild to on a solution file might work, currently i called it to build MyProject.vcxproj. I will need to make some additional solution files but that will be ok. I will try this tomorrow. – smerlin Jun 25 '12 at 22:06
  • OK this worked. I had to create a new solution MyProject.sln, since my main solution contains a lot more projects, which i dont want to build everytime i build MyProject, but it works with the downside that i have to maintain 2 solutions now (if i add an additional dependency for MyProject, i will have to add it to both solutions manually) – smerlin Jun 26 '12 at 14:45
  • for anyone interested in this, it seems that you can avoid maintance of 2 solution files by specifying the `/t:[project_name]` switch http://stackoverflow.com/questions/13915636/specify-project-file-of-a-solution-using-msbuild so for example if LibB has a dependency on LibA, you could do `msbuild solution.sln /t:LibB /p:Configuration="Release"` – bottlenecked May 14 '15 at 21:22
0

I just had the same problem and found that the solution config needed to be done for all configured platforms.