我想使用.NET Core中的Bluetooth LE功能(特别是BluetoothLEAdvertisementWatcher)来编写将信息记录到文件的扫描程序。这将作为桌面应用程序运行,最好是作为命令行应用程序运行。
显然,诸如System.IO.StreamWriter(string)的构造函数不可用。如何创建文件并写入文件?
我将很高兴能够执行System.Console.WriteLine(string),但在.NET Core下也似乎不可用。
更新:为了澄清,如果我可以运行一个看起来像没有错误的程序,那么我将开始比赛。
using System;
using Windows.Devices.Bluetooth.Advertisement;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
BluetoothLEAdvertisementWatcher watcher = new BluetoothLEAdvertisementWatcher();
Console.WriteLine("Hello, world!");
}
}
}
更新2:这是project.json文件:
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
命令的输出dotnet -v run
包含以下错误消息:
W:\src\dotnet_helloworld>dotnet -v run
...
W:\src\dotnet_helloworld\Program.cs(2,15): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
...
这段代码是我提出问题时一直在寻找的骨架。它仅使用.NET Core中可用的功能。
var watcher = new BluetoothLEAdvertisementWatcher();
var logPath = System.IO.Path.GetTempFileName();
var logFile = System.IO.File.Create(logPath);
var logWriter = new System.IO.StreamWriter(logFile);
logWriter.WriteLine("Log message");
logWriter.Dispose();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句