简体   繁体   中英

How to use C# 9 in Blazor WebAssembly project?

I've created a new Blazor WebAssembly project in Visual Studio which, by default, targets .NET Standard 2.1 and therefore uses C# 8.

I've also written a library written for .NET 5 and used C# 9 in it.

How can I use this library in my Blazor project? I can't reference a .NET 5 library in a .NET Standard 2.1 project.

  • When I change the target framework of the library to .NET Standard 2.1 I cannot use C# 9 anymore in the library project. When I explicitly set the LangVersion in the csproj to 9.0 all of my record types get compile errors that some predefined type System.Runtime.CompilerServices.IsExternalInit is not defined
  • When I change the target framework of the Blazor project to .NET 5 and reference a .NET 5 library it doesn't work anymore (start up fails with HTTP Error 500.33 - ANCM Request Handler Load Failure)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM