简体   繁体   English

如何在Blazor WebAssembly项目中使用C# 9?

[英]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.我在 Visual Studio 中创建了一个新的 Blazor WebAssembly 项目,默认情况下,它的目标是 .NET Standard 2.1,因此使用 C# 8。

I've also written a library written for .NET 5 and used C# 9 in it.我还编写了一个为 .NET 5 编写的库,并在其中使用了 C# 9 。

How can I use this library in my Blazor project?如何在我的 Blazor 项目中使用这个库? I can't reference a .NET 5 library in a .NET Standard 2.1 project.我无法在 .NET 标准 2.1 项目中引用 .NET 5 库。

  • When I change the target framework of the library to .NET Standard 2.1 I cannot use C# 9 anymore in the library project.当我将库的目标框架更改为 .NET Standard 2.1 时,我无法再在库项目中使用 C# 9。 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当我将 csproj 中的 LangVersion 显式设置为 9.0 时,我所有的记录类型都会出现一些预定义类型 System.Runtime.CompilerServices.IsExternalInit 未定义的编译错误
  • 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)当我将 Blazor 项目的目标框架更改为 .NET 5 并引用 .NET 5 库时,它不再工作(启动失败,出现 HTTP 错误 500.33 - ANCM 请求处理程序加载失败)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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