c# - 非 Metro 应用程序中的 StorageFile Async 使用

标签 c# windows-8 windows-runtime isolatedstorage async-await

我正在尝试在我的类库中创建一个 StorageFile 实例...

var localFolder = ApplicationData.Current.LocalFolder;
StorageFile destinationFile = await localFolder.CreateFileAsync(destination, CreationCollisionOption.GenerateUniqueName);

VS11 未构建 say: 'await' 要求类型 'Windows.Foundation.IAsyncOperation' 具有合适的 GetAwaiter 方法。您是否缺少“系统”的使用指令?

显然,我正在使用 .net 4.5 作为目标,并且我正在引用 Windows 程序集... 不知道为什么这段代码在 MetroStyle 中工作但不构建在类库中......我如何在类库中创建 Storagefile 的实例???在这个阶段,文件是否以异步方式创建并不重要......

请告诉我你的想法... 斯泰利奥

最佳答案

对我有用的是“手动”添加 TargetPlatformVersion

<PropertyGroup>
  <TargetPlatformVersion>8.0</TargetPlatformVersion>
</PropertyGroup>

并在 Item 组中添加以下内容

<ItemGroup>
  <Reference Include="System.Runtime.WindowsRuntime" />
  <Reference Include="System.Runtime" />
  <Reference Include="Windows" />
</ItemGroup>

然后项目应该可以正常编译。

关于c# - 非 Metro 应用程序中的 StorageFile Async 使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10428446/

相关文章:

windows-runtime - 使用 OCR 引擎识别 Micr 字体?

c# - 您将如何在下拉列表中将特定国家/地区置于首位?

c# - 替代 C# 中的内联?

windows - 如何将当前 Windows 凭据从使用 JS 制作的 Windows 8 native 应用程序传递到 WCF REST 服务?

c++ - Windows 8、C++ 和 Metro GUI 示例?

javascript - Windows 8 商店 javascript 应用程序,从网络下载并保存图像

c# - 将字典作为参数传递给线程函数

c# - 在 c# resharper 中建议 "conditional access", null 给我什么?

c++ - Windows 8 下的 GetVersionEx

c# - ListView : Stretch grid in custom datatemplate to max width?