Skip to content

This open-source project provides a series of NuGet packages that allow you to use the latest C# language features in older versions of .NET.

License

Notifications You must be signed in to change notification settings

dotnet-campus/DotNetCampus.LatestCSharpFeatures

Repository files navigation

Latest CSharp Features

English 简体中文 繁體中文

NuGet

This open-source project provides a NuGet package, dotnetCampus.LatestCSharpFeatures, which allows you to use the latest C# language features in older versions of .NET, including the old .NET Framework, .NET Standard, and older versions of .NET Core App and .NET.

How to Use

Simply install the dotnetCampus.LatestCSharpFeatures NuGet package.

<!-- Since dotnetCampus.LatestCSharpFeatures only contains source generators, it does not introduce any runtime dependencies.
     We can set it to PrivateAssets="all" to avoid passing it on to other projects. -->
<PackageReference Include="dotnetCampus.LatestCSharpFeatures" Version="12.0.0" PrivateAssets="all" />

If you want these new language features to also be effective for other projects that reference this project, you can add a conditional compilation symbol in the csproj file:

<!-- By default, dotnetCampus.LatestCSharpFeatures introduces most new C# features into the current project using the internal modifier.
     By using this conditional compilation symbol, these types can be set to public, allowing other projects referencing this project to also use these new features.
     Note: Index/Range types are always internal and not affected by this setting. See explanation below. -->
<DefineConstants>$(DefineConstants);USE_PUBLIC_LATEST_CSHARP_FEATURES</DefineConstants>

If your project already references other libraries that provide implementations of Index/Range, type conflicts may occur. In such cases, you can disable our Index/Range implementation:

<!-- If your project already has other Index/Range implementations (e.g., through the official System.Runtime.CompilerServices.IndexRange or other third-party libraries),
     use this conditional compilation symbol to disable our Index/Range implementation to avoid type conflicts. -->
<DefineConstants>$(DefineConstants);DISABLE_LATEST_CSHARP_FEATURES_INDEX_RANGE</DefineConstants>

Special Note: Unlike other features, Index/Range types always maintain an internal access level and will not become public due to the USE_PUBLIC_LATEST_CSHARP_FEATURES setting. This is because Index/Range are used in public APIs, and if set to public, they may cause compatibility issues with other libraries that use the official Index/Range implementation. Other features are typically for internal use and do not cause such compatibility issues.

Feedback and Contributions

We welcome feedback and contributions from all users. If you encounter any problems during use, or have any suggestions for improvements, you can submit them via GitHub Issues.

If you wish to participate in the development of the project, you are also very welcome! You can Fork this repository and then submit a Pull Request.

Thank you for your support and help with dotnetCampus.LatestCSharpFeatures!

About

This open-source project provides a series of NuGet packages that allow you to use the latest C# language features in older versions of .NET.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 3

  •  
  •  
  •  

Languages