非 Metro 应用程序中的 StorageFile 异步使用应用程序、Metro、StorageFile

由网友(章鱼小肉丸)分享简介:我正在尝试在我的类库中创建一个 StorageFile 实例...I am trying to create an instance of StorageFile in my class library...var localFolder = ApplicationData.Current.LocalFolder;...

我正在尝试在我的类库中创建一个 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.

阅读全文

相关推荐

最新文章