Skip to content

RuntimeIdentifier in project is not respected when building/publishing as self-contained #25062

@elinor-fung

Description

@elinor-fung

Describe the bug

RuntimeIdentifier in project file is ignored when building/publishing using dotnet build --self-contained or dotnet publish --self-contained. The runtime identifier of the SDK is always used.

To Reproduce

  1. Create a new app
  2. Update the .csproj to specify a RuntimeIdentifier that is not the same as the SDK you are using. For example, when using a Windows x64 SDK, specify:
    <RuntimeIdentifier>win-x86</RuntimeIdentifier>
  3. Build or publish as self-contained:
    dotnet build --self-contained
    dotnet publish --self-contained

Expected: The application is built/published using the RID specified in the project - win-x86.

Actual: The application is built/published using the RID of the SDK - win-x64 - not the one explicitly set in the project.

Further technical details

For the repro steps above, MSBuild ends up invoked with:
-property:RuntimeIdentifier=win-x64 -property:_CommandLineDefinedRuntimeIdentifier=true

The SDK is explicitly adding the RuntimeIdentifier property on the command line if self-contained is specified on the command line, but the runtime identifier is not. As a result, the SDK's RID is used, overriding any settings in the project.

if (!UserSpecifiedRidOption(parseResult) && isSelfContained)
{
var ridProperties = RuntimeArgFunc(GetCurrentRuntimeId());
selfContainedProperties = selfContainedProperties.Concat(ridProperties);
}

Environment info:

.NET SDK (reflecting any global.json):
 Version:   7.0.100-preview.3.22179.4
 Commit:    c48f2c30ee

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22000
 OS Platform: Windows
 RID:         win10-x64

This is a regression from 6.0.

We hit this trying to update the runtime repo to a newer SDK: dotnet/runtime#67771

Metadata

Metadata

Assignees

Labels

Area-CLIgood first issueIssues that would be a good fit for someone new to the repository. Narrow in scope, well-defined.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions