If I execute msbuild from the command line with my solution file or project file as input without setting configuration and platform how does msbuild determine which configuration and platform to use for each project in the solution or the single project file?
1 Answer
In case of solution files - both msbuild and xbuild try to find Debug
config and Mixed platforms
platform, but if that doesn't exist then it falls back to the first one that it can find under SolutionConfigurationPlatforms
in the .sln
file. Keep in mind that this is just solution level config/platform, and it uses the mapping in ProjectConfigurationPlatforms
in the .sln
file to determine the config/platform to use for the project.
In case of project files, the *proj
files usually have the default Configuration
and Platform
specified. But if even that is missing then the Microsoft.Common.*targets
file chooses Debug|AnyCPU
as the default.
Update: default specification in the csproj might look like this:
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
...
It's essentially saying "if $(Configuration) is unspecified, then set it to Debug", and similar for Platform.
-
How are the default
Configuration
andPlatform
specified in the csproj? Also do you happen to know if Microsoft has documented this behavior any where or will I need to dig through theMicrosoft.Common.*targets
and the msbuild code to find this information? I mean I could experiment by creating test solutions and proj files but I didn't want to find out the rules are more complex than what my experimentation exposed. May 10, 2016 at 23:59 -
Understanding Build Configurations: msdn.microsoft.com/en-us/library/kkz9kefa.aspx– radicalMay 11, 2016 at 0:11
-
Thank you, the link is exactly what I have been looking for! Also thanks for the update and I completely forgot those are in each of the project files right at the beginning... May 11, 2016 at 0:25
-
I dont actually see that "msbuild and xbuild try to find the debug config and mixed platforms platform" in the MSDN link (or its current incarnation). Nov 26, 2017 at 4:21