[英]MSIX WPF - Package.InstalledLocation Equivalent
I've created an Windows Application Packaging Project for a WPF app.我为 WPF 应用程序创建了 Windows 应用程序打包项目。 The app runs fine and works with a ClickOnce installer.
该应用程序运行良好,可与 ClickOnce 安装程序一起使用。
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.我在使用 MSIX 时遇到问题,因为我使用的是 appsetings.json 文件,该文件已设置为 BuildAction=Content 并始终复制。 In ClickOnce I can access that file using Directory.GetCurrentDirectory().
在 ClickOnce 中,我可以使用 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".但是在我的 MSIX 版本中,我不断收到一个错误消息,告诉我它找不到该文件,并且它希望在“C:\WINDOWS\system32”中看到它。
I've opened the MSIX Bundle with WinRar and the appsettings.json is in there.我用 WinRar 打开了 MSIX Bundle,appsettings.json 在那里。
In UWP apps I read that you can get the installed location with Package.Current.InstalledLocation.Path.在 UWP 应用程序中,我读到您可以使用 Package.Current.InstalledLocation.Path 获取安装位置。
Is there an equivilant for WPF apps?? WPF 应用程序是否有等价物?
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:在打包的 .NET Core 桌面应用程序中,您应该能够使用
System.AppContext.BaseDirectory
属性获取内容文件的路径:
string absolutePath = System.AppContext.BaseDirectory + "appsetings.json";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.