2

I seem to be having trouble setting the version of .NET used in the Visual Studio editor.

I have a class library that targets several versions of .NET. As you can see in the image below, I've selected .NET 7.0 as the active version. Yet code that is specific to .NET 7.0 and later is grayed out (at least, as indicated by NET7_0_OR_GREATER).

enter image description here

Can anyone tell me how to set the target framework to .NET 7.0 in the editor?

Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
  • Those entries are from your `launchSettings.config` - they do not control the .NET version your project targets: that is controlled by the `` MSBuild property in your `.csproj`. – Dai Jul 16 '23 at 15:15
  • @Dai: As shown in the drop down, my `` tag contains `net7.0`, `net6.0`, `net5.0` and `netstandard2.0`. I'm asking how to specify which of those targets should be used by the editor. – Jonathan Wood Jul 16 '23 at 15:22
  • 2
    Use the top-left drop-down in the Navigation Bar within the VS editor (in your screenshot it says _"Something.Helper (netstandard2.0)"_) - **not** the Start Project button's dropdown side-button. – Dai Jul 16 '23 at 15:55
  • @Dai: Yes, that's it! Thank you. – Jonathan Wood Jul 16 '23 at 15:59

1 Answers1

2

Per Dai's comments, the target I was setting controls what happens when I launch the application (which doesn't make much sense for a class library).

To control the target framework in the editor, use the left of the three drop downs at the top of the edit window.

enter image description here

Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466