We have a visual studio solution with around 150 projects. 5 of these are executable, the other 95 are libraries which the executables reference, or test projects, etc.
Our automated CI builds the solution via MSBuild for both x86 and for x64. However, as the libraries are always built Any CPU, it should be possible to build the full solution Any CPU, and then build the executables again for each platform.
In visual studio, I have 3 solution platforms in the configuration manager, the x86/x64 platforms only build the 5 executables. Within VS, if I build Any CPU first, I can then build the other platforms.
However, I can't get this build to work from msbuild. After building Any CPU, I build x86, and it can't resolve the Project References. That is, /reference: arguments for the library binaries are not passed into csc.exe, and so csc fails because it cannot find any of the types that the binary depends on.
How do I get this to work with MSBuild? How does Visual Studio know to look in bin\Any CPU, but MSBuild does not?
I can't reproduce this issue. Every time if the
CoreCompiletarget executes, it will pass the referenced projectName.dll to csc.exe in my machine. For this, please make sure you're using references in this format to reference project dll:And make sure you didn't add conditions like
Condition="'$(Platform)' == 'AnyCPU'"to ProjectReference element.This is because Configuration Manager. Assuming I have a configuration setting like this:
I have an executable and two library projects in the solution. The executable depends on the two libraries.
1.In vs, when I build the solution with
switch boxset asAny CPU, it actually builds the three projects with platformAny CPU.2.In vs, when I build the solution with
switch boxset asx86, it actually builds the two library projects with platformAny CPU, and builds the executable with x86 platform.3.When I build the solution with Any CPU in msbuild command-line, it works the same as #1.
4.When I build the
executable projectwithx86, it actually builds the three projects all in x86 platform. It's the big difference between VS and command-line.For the difference, you should know the switch box in VS represents
Solution Platforminstead ofProject Platform. So in VS when I set the switch box to x86, it knows for x86 solution platform, it should build libraries inAny CPU, and the executable inX86.However when you build the project in command-line like:
msbuild xx.csproj /p:xxx=x86. It only specify the project platformx86. And since msbuild can find this project depends on two library projects, it will build the library projects in x86 too. (The info about solution configurations and platforms are stored in xx.sln file instead of any xx,csproj file)Since it works in VS when you first build the solution Any CPU and then the five projects X86. I think you can modify the Configuration Manager. For your requirement,you should make sure the relationship between Solution platform and Project platform is:
Don't forget to check the settings in release mode. Then I think it will meet your needs:
as the libraries are always built Any CPU, it should be possible to build the full solution Any CPU, and then build the executables again for each platform.. You should always build with solution file instead of project file:Since the libraries for Any CPU platform will be built when you first build it with Any CPU. In the second and third time, msbuild will only compile and build the executable projects for each platform. And it will skip building libraries again to save time.
Hope it makes some help and if I misunderstand anything, please feel free to correct me :)