'Are there benefits in producing a .NET 6.0 version of a .NET Standard 2.0 library?

If I have a .NET Standard 2.0 library project that is being consumed by a .NET 6.0 console project, are there any performance benefits if I also instruct the compiler to produce a .NET 6.0 version of the library?

I don't plan to use any functionality available on .NET 6.0, I just want to know if the .NET 6.0 version receives extra-love from the compiler.



Solution 1:[1]

Asked the same thing on Twitter, and was fortunate enough to receive feedback from reputed experts Bartosz Adamczewski, Immo Landwerth, Jared Parsons and Lucas Trzesniewski

Here is the question link.

Here are the most relevant bits of info you can extract from the original Twitter thread:

What you might gain is better IL, so things like strings and certain other things are handled better by the front-end compiler C# and better IL is generated, this, in turn, could provide better codegen in JIT - Bartosz Adamczewski

@jaredpar can correct me but for the most part the code gen isn’t depending on the target framework, except for cases where the code gen users specific APIs, which is rare. - Immo Landwerth

That is correct. At the compiler level there is no concept of target frameworks, there are just references. Hence all decisions about code gen are based on the API in the references. - Jared Parsons

In the case of .NET 6, you'll get access to some new APIs such as DefaultInterpolatedStringHandler, so for instance all of your string interpolation expressions ($"...") will get a perf boost just by targeting net6.0. Also, there are new method overloads such as StringBuilder.Append that take string interpolation handlers as parameters. Your string interpolation expressions will target these instead when targeting net6.0, and your code will allocate less than on other targets. So yes, in some cases, your code will get more love by the compiler if you add a net6.0 target ? - Lucas Trzesniewski

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BlueStrat