2

We have a UWP app which references a UWP class library. The UWP class library has a Common folder with files that are required at runtime.

The files are marked Copy As Content. The files are copied to ..\UWP\bin\x64\Debug\Appx\<LibraryName>\Common. The app finds those files at runtime in package.InstalledLocation\<LibraryName>\Common

The UWP class library is now a .NET Standard 2.0 class library. At runtime the Common folder is now copied to a folder at the same level as the Appx folder ..\UWP\bin\x64\Debug\Common where I cannot access. I tried

StorageFolder installedFolder = package.InstalledLocation;
StorageFolder parentFolder = await installedFolder.GetParentAsync();

but parentFolder returns null. How do I access files and folders that are content from a .NET Standard 2.0 class library?

Vague
  • 2,198
  • 3
  • 18
  • 46
  • When your project reference the class library, the `InstalledLocation` just has the .dll file, you can not get the class library's folders and files in the installed location. Basing on my understanding, the class library is better for API reuse but not the resource folders or files, moreover, the UWP app has sandbox and certainly file access permission. – Breeze Liu - MSFT Feb 12 '18 at 05:59
  • Thank you @Breeze Liu - MSFT We have files in that library that we share between projects. Are you saying we must now have a copy of those files in every project? Those files are changing all the time. That would be a maintenance headache. – Vague Feb 12 '18 at 08:27

1 Answers1

2

You can not get the file in the .Net standard class library from the InstalledLocation. To access the files, you can mark the file as Embedded Resource and Copy Always, then expose a method to access the file stream.

Here is a very similar thread, you can see the detailed steps to achieve it,

How to include asset files in a .NET Standard 1.4 library in ARM platform?

Breeze Liu - MSFT
  • 3,734
  • 1
  • 10
  • 13