What is the default msbuild platform

How did msbuild choose a platform if it is not specified? It seems to me that for some solutions he chooses "Mixed platforms" for others "x86".

I turn on the diagnostic logging level, and the only thing I see is that the “Initial Properties” at the beginning contain, for example, “Platform = Mixed Platforms” without explanation.

To preempt some answers, I know that I can redefine the platform manually. It's not a problem. I need to know what msbuild does when it is NOT specified.

+6
source share
2 answers

This may help: I ​​studied this and finally tracked the default platform for my installation by looking at Microsoft.Cpp.Default.props (line 21 in this version of Visual Studio), which lives in Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120 :

 <Platform Condition="'$(Platform)' == ''">Win32</Platform> 

This means that in VS12 (Visual Studio 2013), MSBuild will choose Win32 as the platform if no other platform is explicitly specified. As noted in some other questions, setting an environment variable named Platform will change the default value to the value you specify.

Important Note . If you call MSBuild in the Visual Studio solution file (* .sln), and not in the project file, and you do not specify the platform in the MSBuild arguments, it appears that MSBuild will automatically select the platform based on the first entry in the SolutionConfigurationPlatforms global section in the solution file. I have not found this documented anywhere, but from experiments, it seems to be so. This means that to edit your project file and provide a different default platform property (as described above), MSBuild will ignore the default because it has already selected the platform before it even starts looking at the project. Invoking MSBuild directly in the project file seems to get around this behavior.

+4
source

MSBuild does not select, but any MSBuild project that it creates can use certain properties by default. I assume your question is about how MSBuild creates the solution file.

 msbuild.exe "somesolution.sln" /t:Build 

You need to look at the projects that make up the solution, there you will see the settings that are installed. For example, you will probably see the following at the top of the project file:

 <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> ... </PropertyGroup> 

This shows a PropertyGroup containing, among other things, two properties, Configuration and Platform . Their values ​​are set based on Condition . The condition says that if no value has been set for the Configuration property, it should default to "Debug". Similarly, if nothing is installed for the Platform , it must be set to AnyCPU .

You can also see the Conditional PropertyGroup :

 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> ... </PropertyGroup> 

This condition says that if the Configuration and Platform property matches Debug and AnyCPU , then it should apply all the properties contained inside.

It should be noted that property names are just an arbitrary name, and values ​​are just strings. However, when creating .Net projects, there is an agreement to which these properties and their values ​​are part. To find out what default values ​​you do not need to open each project in a text editor. You can go to Visual Studio and see the solution configuration.

Visual Studio Solution Configuration

+6
source

Source: https://habr.com/ru/post/956083/


All Articles