ShanieMoonlight
ShanieMoonlight

Reputation: 1861

MSIX WPF - Package.InstalledLocation Equivalent

I've created an Windows Application Packaging Project for a WPF app. The app runs fine and works with a ClickOnce installer.

I'm running into a problem with MSIX because I'm using an appsetings.json file, which I've set to BuildAction=Content and Copy Always.

In ClickOnce I can access that file using

Directory.GetCurrentDirectory()

However in my MSIX version I keep getting an error telling me that it can't find the file and that it was expecting to see it in "C:\WINDOWS\system32".

I've opened the MSIX Bundle with WinRar and the appsettings.json is in there.

In UWP apps I read that you can get the installed location with Package.Current.InstalledLocation.Path.

Is there an equivalent for WPF apps??

Upvotes: 1

Views: 449

Answers (1)

mm8
mm8

Reputation: 169400

In a packaged .NET Core desktop app, you should be able to get the path of the content file using the System.AppContext.BaseDirectory property:

string absolutePath = System.AppContext.BaseDirectory + "appsetings.json";

Upvotes: 2

Related Questions