2

I have a .NET Framework 4.8 C# class library project that I want to target to .NET Standard 2.0 for interop with a new .NET 6 project. In the project settings in Visual Studio (tried in both 2019 and 2022, same results), there's no option to target .NET Standard.

enter image description here

If I select "Install other frameworks", it takes me out to the .NET download page. The .NET Standard section on this page says

.NET Standard is a formal specification of .NET APIs that are intended to be available on all .NET implementations. To target .NET Standard in your projects, install one of the SDKs from the .NET/.NET Core table.

Here's a screenshot of that table. Confusingly, no SDKs for VS 2022 or .NET 6 are even listed.

enter image description here

I decide to run dotnet --list-sdks to see what I already have installed, and I get this.

3.1.416 [C:\Program Files\dotnet\sdk]
5.0.203 [C:\Program Files\dotnet\sdk]
5.0.210 [C:\Program Files\dotnet\sdk]
5.0.303 [C:\Program Files\dotnet\sdk]
5.0.403 [C:\Program Files\dotnet\sdk]
5.0.404 [C:\Program Files\dotnet\sdk]
6.0.101 [C:\Program Files\dotnet\sdk]

So it seems that I have everything in place to be able to target .NET Standard 2.0 from this project, but I see no way in Visual Studio to do that. I'm dismayed by how unintuitive this process is. How do I proceed?

Jacob Stamm
  • 1,660
  • 1
  • 29
  • 53
  • 1
    You need an SDK style project. Best to start with the "Class library" project template. Or [this](https://stackoverflow.com/questions/63055430/how-to-create-a-sdk-style-net-framework-project-in-vs) – Hans Passant Jan 21 '22 at 20:38
  • Thank you. I ended up going the route of the [upgrade assistant CLI tool](https://github.com/dotnet/upgrade-assistant), which among other things converts to SDK style projects – Jacob Stamm Jan 21 '22 at 21:48

1 Answers1

1

You could always try setting it by hand in your .csproj by replacing the value of the TargetFramework property with netstandard2.0:

<PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
Etienne de Martel
  • 34,692
  • 8
  • 91
  • 111
  • Funny enough, that's the first thing I tried after posting this, but now all the project's dependencies are barfing on me. I'm going to try the (upgrade assistant)[https://learn.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-overview], which for some reason it took me lots of digging discover – Jacob Stamm Jan 21 '22 at 15:59
  • Which dependencies? Not everything that is in .NET 4.8 exists in Standard 2.0. – Etienne de Martel Jan 21 '22 at 16:02