Giter Site home page Giter Site logo

moh-hassan / compatibility.compilerfeatures Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 39 KB

Compiler tool of the .NET Compiler Platform ("Roslyn") to support c# 11 required feature of net7, init-only and record of c# 9 in the old frameworks net4x, netstandard2.x, NET6 and NET5.

License: MIT License

C# 96.04% Batchfile 3.96%

compatibility.compilerfeatures's Introduction

Compatibility.CompilerFeatures

Nuget

Nuget

Build status

Source only package to support C# 11 required feature and c#9 init and record features in older target frameworks.


C# 11 in net7 added a new feature to support the required keywords as described in required modifier .

When using C# 11 with target frameworks <= NET 7.0, these new features are not possible because the compiler is missing some attribute classes which is used by Roslyn compiler at compile time.

So developers can't use this feature for any target framework prior to NET 7.

This problem can be fixed by referencing Compatibility.CompilerFeatures package. The package is Source code only without binaries.

After the package is installed in the c# project, the missing source code is linked to the project and used by Roslyn compiler during build stage.

The compiled code has no dependency on the package.

These files are used only during build and are not included in your final compiled code.

This means that the resulting project does not have an explicit dependency on the this package. The package also support init and record feature of c# 9.

Supported Framework

The package Compatibility.CompilerFeatures is currently compatible with the following target frameworks:

  • .NET Framework net4x: net472..net45
  • NET 6

c# language feature supported

  • required in c# 11.
  • init-only and record in c# 9.

Note

Other c# language feature in c#8+ may be added in a future releases.

Quickstart

  1. set LangVersion
<LangVersion>latest</LangVersion>
--or--
<LangVersion>preview</LangVersion>
  1. Reference the package

    Add the package Compatibility.CompilerFeatures to c# project:

    dotnet add package Compatibility.CompilerFeatures
    --or--
    Install-Package Compatibility.CompilerFeatures   
    
  2. Ensure that the package has been added as a development dependency
    Open your .csproj file and modify the new package reference to be PrivateAssets:

    <PackageReference Include="Compatibility.CompilerFeatures" Version="<pkg_version>">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>

    With this package declaration your project will have NO explicit dependency on the Compatibility.CompilerFeatures package.

  3. Build the project

    Note:

    • If there is a build error occurs, insure that you use langVersion 11 or preview.
    • Check the sample project included in the repository that support net472, net45 and net6.0.
    • The package is tested with the new c# sdk project format.

Building

Building works in the same way in net7 no more or no less.

Contributing

If something is not working for you, feel free to create an issue and welcome to Pull Request. Contributers can add new features of c# to support the old frameworks.

License

MIT.

See the LICENSE file for details.

compatibility.compilerfeatures's People

Contributors

moh-hassan avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.