Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using new-style csproj with .NET Framework, the default TargetPlatform is x86 rather than AnyCPU #3492

Open
davidmatson opened this issue Jul 30, 2019 · 3 comments
Milestone

Comments

@davidmatson
Copy link

Visual Studio Version:
2019 (16.2.0)

Summary:
When using the new-style (CPS?) csproj but targeting .NET Framework, the default TargetPlatform is differe than either .NET Core or old-style .NET Framework csprojs (x86 rather than AnyCPU).

Steps to Reproduce:

  1. File -> New -> Project -> .NET Core exe

  2. Unload the csproj and replace the target framework line with: <TargetFramework>net472</TargetFramework>

  3. Releoad the project and check its properties

Expected Behavior:
Target platform in AnyCPU.

Actual Behavior:
Target platform is x86.

User Impact:
Confusing behavior when restoring NuGet packages, and inconsistency with all other C# project variants.

@davkean
Copy link
Member

davkean commented Jul 30, 2019

tag @nguerrera

@davkean davkean transferred this issue from dotnet/project-system Jul 30, 2019
@livarcocc livarcocc added this to the Discussion milestone Jul 31, 2019
@chenghuang-mdsol
Copy link

chenghuang-mdsol commented Jun 17, 2021

need to add
<PlatformTarget>AnyCPU</PlatformTarget>
to <PropertyGroup /> as a workaround

@vdrasutis
Copy link

vdrasutis commented Jan 25, 2023

Faced same issue - solved by adding those elements in the "common.sdk.targets" file:

<Project>
  <PropertyGroup Condition="'$(TargetFramework)' == '' And $(TargetFrameworks) == '' ">
    <TargetFramework>net472</TargetFramework>
  </PropertyGroup>

  <PropertyGroup Condition="'$(TargetFramework)' == 'net472' And '$(TargetFrameworks)' == '' And '$(PlatformTarget)' == ''">
    <PlatformTarget>AnyCPU</PlatformTarget>
  </PropertyGroup>
  ...
</Project>

which is imported in every SDK style project like this
<Import Project="$(SourceRoot)\common.sdk.targets" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants