I started with a net6.0
project. And decided to provide netstandard2.0
as internal nuget output for the older supported builds.
Replaced <TargetFramework>net6.0</TargetFramework>
with <TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
in the .proj file. Now have this
The problem though is usage of the nullable reference types. net6.0
and netstandard2.0
are using different language versions
I understand that I would have to do one of these
- Downgrade the language for net6.0
- Create separate projects with certain common files and other separate files
- Use conditional compilation
And I tried the conditional compilation
And it shows that current active framework is netstandard2.0
. I was wondering, how to change that? I added symbols in "Conditional compilation symbols" on the project level, for "Debug and net6.0 Custom symbols". And I was able to switch that way. Now, I set the symbols so that netstandard2.0
is active. I rebuilt and what I see - it compiled for bin\Debug\net6.0
but there is nothing in bin\Debug\netstandard2.0
. And also I get error -
Error CS8630 Invalid 'nullable' value: 'Enable' for C# 7.3. Please use language version '8.0' or greater. projectName (net6.0) C:\DEV\Components\projectName\CSC 1 Active
Not a single file has error inside. All references/packages seem resolving fine. I removed all net6.0-specific pieces in code files. Need some advise here. Thanks
In multi-target projects VS allows switching between the targets for intellisense and syntax highlighting - there is dropdown on the top left of the text editor (I use .NET 7 since I don't have .NET 6 installed):
For the JetBrains Rider users the same is possible by selecting the framework at the bottom of text editor:
Also in my reproducer I have added the conditional attribute to the
Nullable
element in the .csproj:For only nullable you can do it also inline: