There are several articles explaining the new .NET 6 Preview features of Generic Math, often based on this Microsoft article:
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. But in Visual Studio 2022 version 17.0.3 and 17.0.4 (the current release) I simply cannot get this to compile.
I actually went back to VS2022 version 17.0.0 to make sure I had correctly followed the article steps. The code compiles just fine. Upgrade to VS2022 version 17.0.3 and the same project fails to build with the error:
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?
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:
<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.
The complete csproj file, for reference, already containing the extra bits you need, is:
<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>