How do I target .NET Standard 2.0 from my .NET Framework project in Visual Studio? [duplicate]
Asked Answered
H

1

6

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?

Homogenesis answered 21/1, 2022 at 15:44 Comment(2)
You need an SDK style project. Best to start with the "Class library" project template. Or thisFantail
Thank you. I ended up going the route of the upgrade assistant CLI tool, which among other things converts to SDK style projectsHomogenesis
M
2

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>
Moses answered 21/1, 2022 at 15:57 Comment(2)
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)[learn.microsoft.com/en-us/dotnet/core/porting/…, which for some reason it took me lots of digging discoverHomogenesis
Which dependencies? Not everything that is in .NET 4.8 exists in Standard 2.0.Moses

© 2022 - 2024 — McMap. All rights reserved.