简体   繁体   English

当没有为MSBuild指定平台参数时的差异

[英]Difference when platform parameter is/isn't specified for MSBuild

I have a VS10 project file (.csproj). 我有一个VS10项目文件(.csproj)。 I am building this projcet using MSBuild from Command line. 我正在使用命令行中的MSBuild构建此项目。 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 在csproj文件中,我有这个PropertyGroup标记

<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. 我一直在尝试使用命令行中的verbosity参数/ v:d来调查这一点,但除了每个构建的平台不同之外我找不到任何区别。

What would be the platform when I don't pass the platform in command line? 当我不通过命令行传递平台时,平台会是什么? What happens when I pass x86 instead of AnyCPU? 当我通过x86而不是AnyCPU时会发生什么?

Thanks 谢谢

A .csproj file always ensures that a default Platform is selected with this line: .csproj文件始终确保使用以下行选择默认平台:

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

In other words, if the $(Platform) isn't set then it picks a fixed default, AnyCPU in this case. 换句话说,如果没有设置$(平台),那么它会选择一个固定的默认值,在这种情况下为AnyCPU。 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. 它将由该行设置,在这种情况下为AnyCPU。

What happens when I pass x86 instead of AnyCPU? 当我通过x86而不是AnyCPU时会发生什么?

Then you get the Platform selection you asked for, x86. 然后你得到你要求的平台选择,x86。


Do note that <Platform> is rather useless in a pure C# project. 请注意, <Platform>在纯C#项目中相当无用。 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. 它对C ++项目很重要,因为在构建C ++项目时必须使用不同的工具集,它需要使用32位或64位编译器和链接器。 And the compiler/linker for an ARM core is very different from an Intel core. ARM内核的编译器/链接器与英特尔内核有很大不同。 This is not the case for C#, you use the exact same compiler and you get the exact same assembly. 这不是C#的情况,你使用完全相同的编译器,你得到完全相同的程序集。 The jitter is the one that, at runtime, deals with the processor architecture. 抖动是在运行时处理处理器体系结构的抖动。

The only property that makes a difference is <PlatformTarget> . 唯一能与众不同的是<PlatformTarget> You always favor AnyCPU , particularly on class library projects. 你总是喜欢AnyCPU ,特别是在类库项目上。 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. 如果您知道自己依赖于32位非托管代码,则可能需要在EXE项目上使用x86 (首选VS2012中的32位及以上)。 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. 但这是你事先知道的一个事实,当你构建EXE时,选择在AnyCPU和x86之间切换是没有意义的。

It therefore makes no sense to have multiple platforms, just one is enough. 因此,拥有多个平台毫无意义,只需要一个就足够了。 Which ultimately addresses your question, just eliminate the choice. 这最终解决了你的问题,只是消除了选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 QueryString-未指定参数时显示所有条目 - QueryString - Display all entries when parameter isn't specified 当不在AJAX调用过程中时,该参数包含NULL条目 - Parameter contains a NULL entry when it isn't during AJAX call 如果未设置参数类型,是否可以进行SQL注入? - Is SQL Injection possible when parameter's type isn't set? 当未指定&#39;targetFramework&#39;属性时,Nuget不会安装依赖项 - Nuget doesn't install dependencies when 'targetFramework' attribute isn't specified Rider 没有设置我的 msbuild 变量 BuildingInsideVisualStudio - Rider isn't setting my msbuild variable BuildingInsideVisualStudio 使用Func时使用差异的能力差异 <T> 参数 - Difference in ability to use contravariance when using a Func<T> parameter msbuild中的默认平台 - Default platform in msbuild 将新项目添加到ObservableCollection时,“指定的参数超出有效值范围。参数名称:索引” <T> - “Specified argument was out of the range of valid values.Parameter name: index” when adding new item to ObservableCollection<T> 当作为通用参数传递时,为什么不能将通用类型识别为其派生类型? - Why isn't a generic type recognized as its derived type when passed as a generic parameter? MSBuild-根据平台复制文件 - MSBuild - copy files based on platform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM