【发布时间】:2016-02-10 08:27:25
【问题描述】:
我想使用 .NET Core 中的蓝牙 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?)
...
【问题讨论】:
-
它和你需要为 WinRT 做的一样吗? blog.jerrynixon.com/2012/06/…
-
可以分享一下project.json文件吗?您可能缺少一些包引用。
-
@VictorHurdugaci 我已编辑问题以包含我尝试过的 project.json 文件之一,以及产生的错误消息。毫无疑问,参考文献是错误的,我在这里有点失明。这个特定的 project.json 取自 .NET Core 项目的 Visual Studio 2015 项目模板。