How do I get access to Windows.Storage namespace?
Asked Answered
C

2

10

I want to save data to files for my Microsoft Store app, so I need access to Windows.Storage namespace, but it's unclear how I can get it. I couldn't add it as a reference. I'm using Visual Studio 2017 with .NET Framework 4.6.1.

My app is a Windows Forms application that I converted to UWP using the Desktop Bridge.

Cristencristi answered 6/4, 2018 at 8:27 Comment(1)
P
9

The recommended steps to get access to UWP APIs are listed in the dedicated blog post on Windows Blog.

Basically you can take two approaches: add the references to UWP dlls and winmd files manually or use the UwpDesktop-Updated NuGet package that will take care of this for you automatically, but this project doesn't seem to be up to date with the latest SDKs, so the manual approach may be a better solution for you.

Pentahedron answered 6/4, 2018 at 8:44 Comment(4)
One step I would add to that answer is I needed to download this SDK: developer.microsoft.com/en-us/windows/downloads/windows-10-sdkCristencristi
NuGet now have an updated package: UwpDesktop-Updated.Beltz
If you're finding this now, you just have to use the proper TFM with .NET 5+, for example see this error message from upgrading from the Microsoft.Windows.SDK.Contracts (which was the replacement from the solution posted above). learn.microsoft.com/dotnet/core/tools/sdk-errors/netsdk1130 E.g. <TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>Slime
And the TargetFramework in the project file is the same as the Target OS Version in the project's properties page, correct? And the minimum required is 10.0.17763.0, correct? Probably the reason the help page says to edit the project file is that it is easier for the author to explain that.Mutz
A
-1

In Visual Studio 2022 and .NET Framework 4.x

I needed to add the nuget package Microsoft.Windows.SDK.Contracts and then I was able to use the Windows.Storage namespace.

In Visual Studio 2022 and .NET 8

I got an error netsdk1130

< Component name > cannot be referenced. Referencing a Windows Metadata component directly when targeting .NET 5 or higher is not supported.

which leads to that learn Microsoft page netsdk1130.

So I added (changed) the target framework in my csproj-file like it was suggested there.

<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>

and I was able to use the namespace again.

Aer answered 14/3 at 13:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.