C
C#2w ago
Core

✅ Non-nullable property netstandard2.0

Hello, In new .NET versions there's the required keyword for this warning, but what's the best way to solve this if not possible? Recently allowed a library to support older .NET versions, and I have no idea what's the preferred way to resolve this.
No description
20 Replies
Sehra
Sehra2w ago
try setting LangVersion to 11.0 or higher
Core
CoreOP2w ago
it is set to latest
c#
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
c#
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Oh it actually works Great
Core
CoreOP2w ago
No description
Core
CoreOP2w ago
It doesn't afterall
Sehra
Sehra2w ago
it's just attributes, so could include them manually
namespace System.Runtime.CompilerServices;
class RequiredMemberAttribute : Attribute;
class CompilerFeatureRequiredAttribute(string name) : Attribute;
namespace System.Runtime.CompilerServices;
class RequiredMemberAttribute : Attribute;
class CompilerFeatureRequiredAttribute(string name) : Attribute;
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Core
CoreOP2w ago
you mean netstandard 2? Shouldk I completely ditch it?
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Core
CoreOP2w ago
this one not, but the next one will be
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Core
CoreOP2w ago
Got it, most open source propejcts support these, and that's why I was trying it out
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Core
CoreOP2w ago
Is netstandard 2.1 only used by unity?
Core
CoreOP2w ago
No description
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Core
CoreOP2w ago
yeah I diteched it Thanks for the details How does this work? I get that it will enable all the new syntaxes that are possible in newer .NET versions, like nullable types, required properties, etc. But what happens after building the package, and required was used? Will it simply be omitted in the compiled executable?
Sehra
Sehra2w ago
required is only an attribute as i understand it roslyn only looks for specific attributes, and it doesn't matter where they are defined
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Core
CoreOP2w ago
Great, I read the wiki, but I still couldn't entirely understand how it works Thank you again for helping me $close
MODiX
MODiX2w ago
If you have no further questions, please use /close to mark the forum thread as answered

Did you find this page helpful?