How do you access the asset folder in an unpackages application? #3175
Replies: 2 comments 1 reply
-
Try this public static string GetFullPathToExe()
{
var path = AppDomain.CurrentDomain.BaseDirectory;
var pos = path.LastIndexOf("\\");
return path.Substring(0, pos);
}
public static string GetFullPathToAsset(string assetName)
{
return GetFullPathToExe() + "\\Assets\\" + assetName;
} |
Beta Was this translation helpful? Give feedback.
-
If you are adding these files to the project, are these being added to the resources.pri file? If they are, you can easily query for a resource file, and it will provide a full path to that file. As an example, I have a project that had a bunch of png files added. If I dump the contents of the resource index file, using the command line makepri dump /if resources.pri, then the generated file contains entries such as:
As you should see, this does give a path to the files added to the project. If I use the resource manager API to query for this:
Then the value that I get in the text block that I named resourcePath is: The resources API calculates the path for you. While this is C++, the same method should work for C# too. The only issue is that the unpackaged project builds don't always create resources.pri. I think this normally gets generated as part of the packaging process. It is easy enough to deal with this, if you only have one .pri file then just copy that to resources.pri. If you are using components that also have .pri files, then you would have to merge them or access each .pri file. If there is no .pri files, then I agree with ghost1372's suggestion of getting the base application directory and working from there. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
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;
Beta Was this translation helpful? Give feedback.
All reactions