JetBrains Rider 无法识别属性生成的构造函数

JetBrains Rider does not recognize the constructor generated by the attribute

下面代码中的

[AutoConstructor]会自动生成一个构造函数(如下图所示):

在Visual Studio中运行良好,但JetBrains Rider出现错误信息:

我不明白。 . .

(因为我英文不好,所以用的是Google翻译提问,请见谅)

using System;
using System.Linq;
using ComputeSharp;

namespace ComputeSharpTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // Allocate a writeable buffer on the GPU, with the contents of the array
            // Get some sample data
            int[] array = Enumerable.Range(1, 1000000).ToArray();

            // Allocate a GPU buffer and copy the data to it.
            // We want the shader to modify the items in-place, so we
            // can allocate a single read-write buffer to work on.
            using ReadWriteBuffer<int> buffer = Gpu.Default.AllocateReadWriteBuffer(array);
            
            // Launch the shader
            Gpu.Default.For(buffer.Length, new MultiplyByTwo(buffer));

            // Get the data back
            buffer.CopyTo(array);
        }
    }

    [AutoConstructor]
    public readonly partial struct MultiplyByTwo : IComputeShader
    {
        public readonly ReadWriteBuffer<int> buffer;

        public void Execute()
        {
            buffer[ThreadIds.X] *= 2;
        }
    }

}

根据https://github.com/Sergio0694/ComputeSharp/issues/116 (and also https://github.com/Sergio0694/ComputeSharp#requirements):

In order to work correctly, ComputeSharp also needs the source generator to be added to consuming projects as an analyzer, so that it can run when the code is being compiled.

You can do so by adding the following code to your .csproj file, just like in the sample projects:

<ItemGroup>
    <ProjectReference Include="..\..\src\ComputeSharp\ComputeSharp.csproj" />
    <ProjectReference Include="..\..\src\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj"
                      OutputItemType="Analyzer"
                      ReferenceOutputAssembly="false"
                      PrivateAssets="contentfiles;build" />
  </ItemGroup>

此外,您需要确保您使用的是 .NET 5(不是 .NET Framework/Core 的早期版本)。

如果您的问题仍然存在,您不妨尝试使用 VS 2019 而不是 Rider。