简体   繁体   English

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

[英]JetBrains Rider does not recognize the constructor generated by the attribute

[AutoConstructor] in the code below will automatically generate a constructor (as shown in the figure below):下面代码中的[AutoConstructor]会自动生成一个构造函数(如下图):
在此处输入图片说明

It works fine in Visual Studio, but JetBrains Rider has an error message:它在 Visual Studio 中运行良好,但 JetBrains Rider 有一条错误消息:
在此处输入图片说明

I do not understand.我不明白。 . . . .

(Because I am not good at English, I am using Google Translate to ask questions, please forgive me) (因为英语不好,所以用谷歌翻译提问,请见谅)

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;
        }
    }

}

As per https://github.com/Sergio0694/ComputeSharp/issues/116 (and also https://github.com/Sergio0694/ComputeSharp#requirements ):根据https://github.com/Sergio0694/ComputeSharp/issues/116 (以及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.为了正常工作,ComputeSharp 还需要将源生成器作为分析器添加到消费项目中,以便在编译代码时可以运行。

You can do so by adding the following code to your .csproj file, just like in the sample projects:您可以通过将以下代码添加到 .csproj 文件来实现,就像在示例项目中一样:

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

Additionally, you need to ensure you are using .NET 5 (not an early version of .NET Framework / Core).此外,您需要确保您使用的是 .NET 5(不是 .NET Framework/Core 的早期版本)。

If your issue persists, you may also wish to try using VS 2019 rather than Rider.如果您的问题仍然存在,您可能还希望尝试使用 VS 2019 而不是 Rider。

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

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