c# - .NET Core编译错误:找不到类型或 namespace 名称 'LibGpiodDriver'

标签 c# linux .net-core compiler-errors

当我尝试在主机上构建C#代码(自包含发布)时,发生错误,提示缺少参考:

Program.cs(23,90): error CS0246: The type or namespace name 'LibGpiodDriver' could not be found (are you missing a using directive or an assembly reference?)
这是我的源代码 Program.cs 文件:
using System;
using System.Device.Gpio;
using System.Threading;

namespace led_blink
{
    class Program
    {
        static void Main(string[] args)
        {
            var pin = 81;
            var lightTimeInMilliseconds = 1000;
            var dimTimeInMilliseconds = 200;
            
            Console.WriteLine($"Let's blink an LED!");

        using (GpioController controller = new GpioController(PinNumberingScheme.Board, new LibGpiodDriver()))
            //using (GpioController controller = new GpioController())
            {
                controller.OpenPin(pin, PinMode.Output);
                Console.WriteLine($"GPIO pin enabled for use: {pin}");

                Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs eventArgs) =>
                {
                    controller.Dispose();
                };

                while (true)
                {
                    Console.WriteLine($"Light for {lightTimeInMilliseconds}ms");
                    controller.Write(pin, PinValue.High);
                    Thread.Sleep(lightTimeInMilliseconds);
                    Console.WriteLine($"Dim for {dimTimeInMilliseconds}ms");
                    controller.Write(pin, PinValue.Low);
                    Thread.Sleep(dimTimeInMilliseconds);
                }
            }
        }
    }
}
这是我的 .csproj 文件:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Iot.Device.Bindings" Version="1.0.0" />
    <PackageReference Include="System.Device.Gpio" Version="1.0.0" />
  </ItemGroup>

</Project>
我正在使用Linux终端而不是任何IDE来完成工作。

最佳答案

LibGpiodDriver类型在System.Device.Gpio.Drivers命名空间中(请参阅 LibGpiodDriver )
添加using System.Device.Gpio.Drivers;

关于c# - .NET Core编译错误:找不到类型或 namespace 名称 'LibGpiodDriver',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62533176/

相关文章:

python - 使用 turbodbc 从 Python 访问 Linux 上的 Postgres

linux - 如何将字符串拆分为单个字符

sql-server - SQL Server Always Encrypted 与 .NET Core 不兼容

c# - 如何对使用控制台类的类进行单元测试?

c# - In 和 Out 属性在 .NET 中如何工作?

php - 如何将表从一个数据库复制到不同服务器的另一个数据库

c# - 如何使用 C# DateTime.TryParse(最简单的方法)

asp.net-core - .NET Core 中 AssemblyBuilder.DefineDynamicAssembly 的替换

c# - 响应 &lt;input&gt; 字段中的 "enter"按键

c# - FlowLayoutPanel AutoSize 仅在垂直方向?