Search code examples
c#buildprojects-and-solutionsvisual-studio-2022.net-standard-2.0

.netstandard 2.0 project Always compiles to AnyCPU


We have a large solution with many projects. We are moving from .NET4.8 to .NET6 (eventually). To get started, we are changing some projects to .NetStandard2.0.

Our first test is to modify one interface to .NetStandard2.0. This should work since the interface has 0 dependencies.

Note: Due to some device drivers we need to build with x86 configuration (this will change in the future).

I created a test solution targeting .NetStandard2.0 and it works well (I can build to x86 or x64 as needed).

I copied the project into the large solution and it will only build to Any CPU.

The .csprojfile looks the same in both solutions:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <PlatformTarget>x86</PlatformTarget>
  </PropertyGroup>

</Project>

But when I build the solution, I get:

1>------ Build started: Project: MyTestInterface, Configuration: Debug Any CPU ------

The rest of the projects in the solution build to x86 (or x64 if asked). When I look in the Configuration Manager, for this one project Any CPU is the only option - even though it does not exist in any other project or configuration. If I try to create a New configuration I get:

This platform could not be created because a solution
platform with the same name already exists.

How do I get this .NetStandard2.0 project to build to x86 (or x64)?


Solution

  • With two people working on this for a couple of days, we have it working as it should now. The only issue left is that we must manually edit the .csproj files for every .NetStandard2.0 project in the solution.

    To fix it, we replaced the "PlatformTarget" line with:

    <Platforms>x64;x86</Platforms>
    

    Unfortunately, the "PlatformTarget" line is added if we try to make changes in the Configuration Manager and we, then, must edit the .csproj file again.