Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ Copyright (c) .NET Foundation. All rights reserved.

<!-- Determine PlatformTarget (if not already set) from runtime identifier. -->
<Choose>
<!-- For all targets other than .NETFramework, set $(PlatformTarget) to AnyCPU.

Outside .NET Framework, PlatformTarget does not have a real purpose since the process architecture is
determined by the host used to launch the application. Defaulting to AnyCPU naturally works on all platforms
where modern .NET is supported and makes it unnecessary to recognize these platforms as PlatformTargets.
-->
<When Condition="'$(PlatformTarget)' == '' and '$(TargetFrameworkIdentifier)' != '.NETFramework' and '$(UseNativeCode)' != 'true'">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is UseNativeCode a pre-existing property or is this a new property introduced by this PR?

If it is a new property introduced to disable the new behavior, it should have a specific name, something like UseSpecificPlatformTargetIfPossible.

Copy link
Member Author

@am11 am11 Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used in a test project which is failing on .NET Framework, so I added it here temporarily to check if that's the only issue. It turned out it's not the only problem there. Tests are written in a way that diverging behavior is tricky to assert.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the latest conversation (#48599 (comment)), should the UseNativeCode condition be deleted here?

<PropertyGroup>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
</When>

<When Condition="'$(PlatformTarget)' != '' or '$(RuntimeIdentifier)' == ''" />

<When Condition="$(RuntimeIdentifier.EndsWith('-x86')) or $(RuntimeIdentifier.Contains('-x86-'))">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Copyright (c) .NET Foundation. All rights reserved.
<!--
NOTE:

• For all targets other than .NETFramework, set $(PlatformTarget) to AnyCPU.

* We cannot compare against $(Platform) directly as that will give VS cause to instantiate extra
configurations, for each combination, which leads to performance problems and clutter in the sln
in the common AnyCPU-only case.
Expand All @@ -67,6 +69,7 @@ Copyright (c) .NET Foundation. All rights reserved.
outside the 1:1 defaults below.
-->
<PropertyGroup>
<PlatformTarget Condition=" '$(PlatformTarget)' == '' and '$(TargetFrameworkIdentifier)' != '.NETFramework' and '$(UseNativeCode)' != 'true' ">AnyCPU</PlatformTarget>
<_PlatformWithoutConfigurationInference>$(Platform)</_PlatformWithoutConfigurationInference>
</PropertyGroup>
<PropertyGroup Condition=" '$(_PlatformWithoutConfigurationInference)' == 'x64' ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void It_publishes_the_project_with_a_refs_folder_and_correct_deps_file(st

dependencyContext.CompilationOptions.Defines.Should().Contain(expectedDefines);
dependencyContext.CompilationOptions.LanguageVersion.Should().Be(langVersion);
dependencyContext.CompilationOptions.Platform.Should().Be("x86");
dependencyContext.CompilationOptions.Platform.Should().Be(appTargetFramework == "net46" ? "x86" : "AnyCPU");
dependencyContext.CompilationOptions.Optimize.Should().Be(false);
dependencyContext.CompilationOptions.KeyFile.Should().Be("");
dependencyContext.CompilationOptions.EmitEntryPoint.Should().Be(true);
Expand Down
Loading