Home > Software engineering >  How do you access the asset folder in an unpackaged Windows SDK application?
How do you access the asset folder in an unpackaged Windows SDK application?

Time:11-26

I added this to the csproj file

<ItemGroup> 
  <None Update="Assets/*">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory> 
  </None> 
</ItemGroup>

so I can access the asset folder after an install.

However, I can not find any documentation or help on how to access these files. I found this page: https://learn.microsoft.com/en-us/uwp/api/windows.storage.storagefolder.getfolderfrompathasync?view=winrt-22621 , but when I try it out, this line throws an InvalidOperationException

string root = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

CodePudding user response:

I use the following code to read files in a unpackaged WindowsAppSDK test project. My files are copied to output directory with <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>.

string folderName = Path.Combine(Path.GetDirectoryName(typeof(App).Assembly.Location), "Assets");
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(folderName);

CodePudding user response:

I asked on the Github for WindowsAppSDK and they gave me this solution

string folder = AppDomain.CurrentDomain.BaseDirectory   @"Assets\";
  • Related