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 异步使用
基础教程推荐
- 如何激活MC67中的红灯 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- SSE 浮点算术是否可重现? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01