StorageFile Async usage in a NON Metro application(非 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 异步使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:非 Metro 应用程序中的 StorageFile 异步使用
基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
