Why does MSBuild require explicit configuration of the target platform?

For my simple project, the final build in Visual Studio creates an assembly of 18.944 bytes in size. But if I build the same solution from the command line with MSBuild, I get an assembly of 28,672 bytes in size. This is a difference of 9,728 bytes.

I invoke MSBuild with:

msbuild /p:Configuration=Release /t:Rebuild MySolution.sln

In ILDasm, I saw only slight differences in metadata. Dumping and comparing a tree view show no differences. Dropping and comparing the headers gave the key:

Visual Studio Output                             MSBuild Output
// Size of init.data:              0x00000800    // Size of init.data:              0x00002000
// Size of headers:                0x00000200    // Size of headers:                0x00001000
// File alignment:                 0x00000200    // File alignment:                 0x00001000

The difference in the size of the initialization data is 0x1800 or 6144 bytes. The difference in header size is 0xE00 or 3,584 bytes. The sum of these two differences is 9,728 bytes, which explains the discrepancy. The difference in file alignment is 3,584 bytes.

Next I see:

Visual Studio Output                                    MSBuild Output
// File size            : 18944                         // File size            : 28672
// PE header size       : 512 (496 used)    ( 2.70%)    // PE header size       : 4096 (496 used)    (14.29%)
// Data                 : 2048              (10.81%)    // Data                 : 8192              (28.57%)

, , . ? Visual Studio , 512:

alt text

PropertyGroup:

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

$Configuration $Platform? , :

msbuild /p:Configuration=Release /p:Platform="Any CPU" /t:Rebuild MySolution.sln

( ) !

, MSBuild , . , OutputPath MSBuild . , .

512 1024, . !

, MSBuild 512 ?

+3
2

, , FileAlignment , Visual Studio ( ). VS2008 VS2010 ( , VS2005 VS2008 ), , - .

, , , , . , ( ), , , , FileAlignment .

+2

, , Debug|AnyCPU. <PropertyGroup> , - :

<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>

, Configuration Platform . .

+4

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


All Articles