简体   繁体   English

如何在 Visual Studio 2022 中使用 .NET 6 Preview Generic Math?

[英]How to use .NET 6 Preview Generic Math in Visual Studio 2022?

There are several articles explaining the new .NET 6 Preview features of Generic Math, often based on this Microsoft article:有几篇文章解释了通用数学的新 .NET 6 预览功能,通常基于此 Microsoft 文章:

https://devblogs.microsoft.com/dotnet/preview-features-in-net-6-generic-math/ https://devblogs.microsoft.com/dotnet/preview-features-in-net-6-generic-math/

In the preview versions, and the first release of Visual Studio 2022 this works fine.在预览版和 Visual Studio 2022 的第一个版本中,这可以正常工作。 But in Visual Studio 2022 version 17.0.3 and 17.0.4 (the current release) I simply cannot get this to compile.但是在 Visual Studio 2022 版本 17.0.3 和 17.0.4(当前版本)中,我根本无法编译它。

I actually went back to VS2022 version 17.0.0 to make sure I had correctly followed the article steps.我实际上回到了 VS2022 版本 17.0.0 以确保我正确地遵循了文章中的步骤。 The code compiles just fine.代码编译得很好。 Upgrade to VS2022 version 17.0.3 and the same project fails to build with the error:升级到VS2022版本17.0.3,同一个项目构建失败,报错:

Error   CS0246  The type or namespace name 'INumber<>' could not be found (are you missing a using directive or an assembly reference?)

Anyone got any ideas?有人有什么想法吗? I assume I have to make a further change to the csproj file, but what change?我假设我必须对 csproj 文件进行进一步更改,但是有什么更改呢?

In the NuGet Package Manager I found the option to upgrade System.Runtime.Experimental to version 6.0.0, which changed the entry in my csproj file from:在 NuGet Package 管理器中,我找到了将 System.Runtime.Experimental 升级到版本 6.0.0 的选项,这将我的 csproj 文件中的条目从:

  <ItemGroup>
    <PackageReference Include="System.Runtime.Experimental" Version="6.0.0-preview.7.21377.19" />
  </ItemGroup>

to:至:

  <ItemGroup>
    <PackageReference Include="System.Runtime.Experimental" Version="6.0.0" />
  </ItemGroup>

rebooting doesn't help.重新启动没有帮助。 Cleaning the solution doesn't help.清洁溶液无济于事。 I am not seeing anything to help me in the release notes for Visual Studio 2022 either.在 Visual Studio 2022 的发行说明中,我也没有看到任何可以帮助我的东西。

The complete csproj file, for reference, already containing the extra bits you need, is:完整的 csproj 文件供参考,已经包含您需要的额外位,是:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net6.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <EnablePreviewFeatures>True</EnablePreviewFeatures>
        <LangVersion>preview</LangVersion>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="System.Runtime.Experimental" Version="6.0.0" />
    </ItemGroup>
</Project>

Step 1步骤1

As explained in the blog article you've linked at the top of the question: add正如您在问题顶部链接的博客文章中所解释的那样:添加

    <EnablePreviewFeatures>true</EnablePreviewFeatures>

into a <PropertyGroup> element in your project file.到项目文件中的<PropertyGroup>元素中。

Step 2第2步

Now the above is confirmed: have you tried the preview version of VS2022 (currently V17.1 Preview 1.1)?现在上面已经确认了:你试过VS2022的预览版(目前是V17.1 Preview 1.1)吗?

Just tried it: No.刚试了一下:没有。

Step 3第 3 步

See Hans Passant's comment on to the question: need to wait on this (or do you own builds of what is being built to be .NET 7...)请参阅Hans Passant 对问题的评论:需要等待这个(或者您是否拥有正在构建的 .NET 7 的构建......)

I got the same error with VS2022 17.0.4.我在 VS2022 17.0.4 中遇到了同样的错误。 Now, VS2022 17.1.0 Preview 1.1 seems to work fine.现在,VS2022 17.1.0 Preview 1.1 似乎工作正常。

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

相关问题 Swagger 打开并在 .NET 6 MacOS Visual Studio 2022 预览版中出现错误 1 - Swagger open and giving a error in .NET 6 MacOS Visual Studio 2022 preview 1 如何在 Visual Studio 2022 预览版中调试 .Net Core 项目时禁用内部终端 - How to disable internal terminal while debugging for .Net Core projects in Visual Studio 2022 preview 如何在 Visual Studio 2022 预览版中禁用 CS1514 - How to disable CS1514 in Visual Studio 2022 preview 如何在 Visual Studio 2022 Preview 中禁用代码分析? - How to disable code analysis in Visual Studio 2022 Preview? 如何在 Visual Studio 2022 和 .net Standard 2.0 或 .net 4.8 中使用 CallerArgumentExpression? - How can I use CallerArgumentExpression with Visual Studio 2022 and .net Standard 2.0 or .net 4.8? 在 Visual Studio 2022 中使用自定义 .NET Core 模板 - Use custom .NET Core templates in Visual Studio 2022 Visual Studio 2019 和 2022(预览版)在启动时找不到 .NET 6 SDK - mac osx - Visual Studio 2019 & 2022 (Preview) not finding .NET 6 SDK on launch - mac osx Visual Studio for Mac 2022 不使用预期的 .NET6 SDK - Visual Studio for Mac 2022 does not use expected .NET6 SDK 在 Visual Studio 2022 中使用 Git - Use Git in Visual Studio 2022 如何存储在 Visual Studio 2022 中? - How to stash in Visual Studio 2022?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM