非 Metro 应用程序中的 StorageFile 异步使用 [英] StorageFile Async usage in a NON Metro application

查看:15
本文介绍了非 Metro 应用程序中的 StorageFile 异步使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to create an instance of StorageFile in my class library...

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

VS11 没有构建说:'await' 要求类型 'Windows.Foundation.IAsyncOperation' 具有合适的 GetAwaiter 方法.您是否缺少系统"的 using 指令?

VS11 is not building say: 'await' requires that the type 'Windows.Foundation.IAsyncOperation' have a suitable GetAwaiter method. Are you missing a using directive for 'System'?

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

obviously I am using .net 4.5 as target and I am referencing Windows Assemblies... not sure why this code work in MetroStyle but does not build in a class library... How can I create an instance of Storagefile in a class library??? at this stage it is not important if the file is created in an async way...

请告诉我你的想法...斯特里奥

pls let me know your thoughts... Stelio

推荐答案

对我有用的是手动"添加 TargetPlatformVersion

What worked for me is to "manually" add the TargetPlatformVersion

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

并在项目组中添加以下内容

and in Item group add the following

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

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

Then the project should compile normaly.

这篇关于非 Metro 应用程序中的 StorageFile 异步使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆