I have a VS10 project file (.csproj). I am building this projcet using MSBuild from Command line. I have a simple question which I have been trying to figure out since a long time. What is the difference between these command line arguments :-
1. >MSBuild MyProg.csproj /p:Configuration="Release"
2. >MSBuild MyProg.csproj /p:Platform="AnyCPU" /p:Configuration="Release"
3. >MSBuild MyProg.csproj /p:Platform="x86" /p:Configuration="Release"
In the csproj file I have this PropertyGroup tag
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
I want to know what difference does it make when you specify the platform in command line arguments and when you don't. I have been trying to investigate this using the verbosity parameter /v:d in the command line, but I could not find any difference except that the platform is different for each build.
What would be the platform when I don't pass the platform in command line? What happens when I pass x86 instead of AnyCPU?
Thanks
A .csproj file always ensures that a default Platform is selected with this line:
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
In other words, if the $(Platform) isn't set then it picks a fixed default, AnyCPU in this case. If you intentionally removed this line then you want to restore it. Or add it if it was never there. Which allows addressing your questions:
What would be the platform when I don't pass the platform in command line?
It will be set by that line, AnyCPU in this case.
What happens when I pass x86 instead of AnyCPU?
Then you get the Platform selection you asked for, x86.
Do note that <Platform>
is rather useless in a pure C# project. It matters a great deal to a C++ project because a different toolset must be used when the C++ project is built, it requires using either a 32-bit or 64-bit compiler and linker. And the compiler/linker for an ARM core is very different from an Intel core. This is not the case for C#, you use the exact same compiler and you get the exact same assembly. The jitter is the one that, at runtime, deals with the processor architecture.
The only property that makes a difference is <PlatformTarget>
. You always favor AnyCPU
, particularly on class library projects. You may want to use x86
on the EXE project (Prefer 32-bit in VS2012 and up) if you know that you have a dependency on 32-bit unmanaged code. But that's a hard fact you know up front, it doesn't make sense to have the option to switch between AnyCPU and x86 when you build the EXE.
It therefore makes no sense to have multiple platforms, just one is enough. Which ultimately addresses your question, just eliminate the choice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With