sdk: Dotnet build and publish don't have parameters for platform

Steps to reproduce

Have a csproj file with conditional configs as such: <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">

Expected behavior

There’s a configuration parameter (dotnet build -c Debug) (dotnet publish -c Debug) that fills in $(Configuration) so I expect there to be a parameter to fill in $(Platform)

Actual behavior

There is no parameter and specific configuration details don’t get applied because Platform does not get set to x64

Current Work-around

Explicitly setting the Platform EV for the current command prompt using SET Platform=x64

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 9
  • Comments: 20 (8 by maintainers)

Most upvoted comments

You can pass it using dotnet build /p:Platform=x64

Shouldn’t that be added to the documentation then?

Usage: dotnet build [options] <PROJECT>

Arguments:
  <PROJECT>   The project file to operate on. If a file is not specified, the command will search the current directory for one.

Options:
  -h, --help                            Show command line help.
  -o, --output <OUTPUT_DIR>             The output directory to place built artifacts in.
  -f, --framework <FRAMEWORK>           The target framework to build for. The target framework must also be specified in the project file.
  -c, --configuration <CONFIGURATION>   The configuration to use for building the project. The default for most projects is 'Debug'.
  -r, --runtime <RUNTIME_IDENTIFIER>    The target runtime to build for.
  --version-suffix <VERSION_SUFFIX>     Set the value of the $(VersionSuffix) property to use when building the project.
  --no-incremental                      Do not use incremental building.
  --no-dependencies                     Do not build project-to-project references and only build the specified project.
  --no-restore                          Do not restore the project before building.
  -v, --verbosity <LEVEL>               Set the MSBuild verbosity level. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].
  --force                               Force all dependencies to be resolved even if the last restore was successful.
                                        This is equivalent to deleting project.assets.json.

I’ve spent at least an hour on this issue, tracking it down to something not obvious from the beginning: dotnet build requires a minus - for -c and a slash / for /p. Many command line parses allow - and / to be used interchangeably.

dotnet build -c:"Debug" /p:Platform:"Any CPU"

Note for scripting: the Configuration and Platform names should be in quotes, as these are arbitrary names that can contain spaces. The defaults are “Debug”/“Release” and “Any CPU”, but you could rename them to “Custom Configuration Name” and “Custom Platform Name”.

Note: The “Any CPU” Platform by default produces AnyCPU (no space) output, but that can changed per project. The “Any CPU” Platform may produce one project as AnyCPU, one as x86 and another as x64. For more information, study the “Configuration Manager” in Visual Studio.

What worked for me was /p:Platform= and not /p:Platform:

That’s works for me https://github.com/dotnet/sdk/issues/9966#issuecomment-443468788

But why it’s not documented until now !!

In .NET 6, you can use the -a|--arch argument to specify the architecture of your build/publish/etc. See detailed documentation here. This doesn’t handle the general case where users might want an AnyCPU value for the Platform MSBuild property, however.

That’s works for me #9966 (comment)

But why it’s not documented until now !!

Valid question.

EDIT: it is documented, but not in an optimal way. I think the -p argument should be a part of the synopsis and also be added to the Arguments section.

I’ve spent at least an hour on this issue, tracking it down to something not obvious from the beginning: dotnet build requires a minus - for -c and a slash / for /p. Many command line parses allow - and / to be used interchangeably.

dotnet build -c:"Debug" /p:Platform:"Any CPU"

Note for scripting: the Configuration and Platform names should be in quotes, as these are arbitrary names that can contain spaces. The defaults are “Debug”/“Release” and “Any CPU”, but you could rename them to “Custom Configuration Name” and “Custom Platform Name”.

Note: The “Any CPU” Platform by default produces AnyCPU (no space) output, but that can changed per project. The “Any CPU” Platform may produce one project as AnyCPU, one as x86 and another as x64. For more information, study the “Configuration Manager” in Visual Studio.