当我尝试在主机上构建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;
。