How to add C# record
support or init
support in a .NET Standard 2.0 library.
Just change your project to use the latest C# language version and add this nuget package.
In .NET Standard 2.0, change your .csproj to use the latest lang version by adding the LangVersion
element:
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>
As a Project Reference:
<PackageReference Include="dotnetKyle.IsExternalInit" version="1.0.0" />Using the CLI:
dotnet add package dotnetKyle.IsExternalInitUsing the Package Manager Console:
Install-Package dotnetKyle.IsExternalInit
To test, rebuild your project to get your record
or init
setter to start working.
Alternatively, you can create a test record:
public record MyRecord(string MyString);
Then build your project.