看起来你正试图从WinRT的使用类型因为StorageFile
class documentation指出它仅适用于Metro,它在Windows.Storage
中找到。
This blog post经历了如何构建它,但它似乎是一个手动过程。它还详细介绍了错误的原因:
Using the await keyword causes the compiler to look for a GetAwaiter method on this interface. Since IAsyncOperation does not define a GetAwaiter method, the compiler wants to look for an extension method.
基本上,它看起来像你需要添加一个引用:System.Runtime.WindowsRuntime.dll
请花时间阅读他的博客,但我会为了清楚起见,将重要部分放在这里
博客内容下方毫不客气地雷同
首先,在记事本中,我创建了EnumDevices.cs下面的C#代码:
using System;
using System.Threading.Tasks;
using Windows.Devices.Enumeration;
using Windows.Foundation;
class App {
static void Main() {
EnumDevices().Wait();
}
private static async Task EnumDevices() {
// To call DeviceInformation.FindAllAsync:
// Reference Windows.Devices.Enumeration.winmd when building
// Add the "using Windows.Devices.Enumeration;" directive (as shown above)
foreach (DeviceInformation di in await DeviceInformation.FindAllAsync()) {
Console.WriteLine(di.Name);
}
}
}
其次,我创建了一个BUILD.BAT文件,我从开发人员命令提示符来建立此代码(这应该是1行,但我在这里包装它的读能力):
csc EnumDevices.cs
/r:c:\Windows\System32\WinMetadata\Windows.Devices.Enumeration.winmd
/r:c:\Windows\System32\WinMetadata\Windows.Foundation.winmd
/r:System.Runtime.WindowsRuntime.dll
/r:System.Threading.Tasks.dll
然后,在命令提示符处,我只运行EnumDevices.exe来查看输出。
在Metro风格中,代码文件顶部是否还有额外的使用语句? –
有相同的使用... –