简体   繁体   中英

how to include application file dependencies in MSIX package?

I have a C# WPF .NETCORE application which I've written myself and now need to produce a MSIX installer for it.

In the C# project I have various configuration files (*.json, *.csv, *.xml) which the application needs at launch to set the state for the application (api locations etc).

When I run the app from Visual Studio debugger it works fine in debug or release.

When I "Publish" from the publish options in VS it work if I manually copy the files to the same level as the published single file executable.

When I package with Windows Application Package Project in VS (with my wpf application referenced as a project reference) the application is packaged, I can install and execute but it crashes when it tried to load the.json files.

A logo image that I have in the same folder as the config stuff (the directory is called Resources with subs of /images, /configs, etc) as is referenced by the xaml as "Resources/Images/logo.png" is loading fine. The configs are loaded at app start and reference "Resources/Configs/api.json"

I can see that the Resources directory is being included in the build but when I run a cmd in the app-package, the app is being launched in system32, which makes sense that it isn't loading from the relative path to the executable location.

I suspect that I am not including the resources in the WPF application in a modern MSIX way and need to fix that rather than crowbar my resources into the msix? or maybe I just need to include my Resources so other way?

Thanks for your help

edit:

@MM8

when the main window launches. Depending on which option is selected in said window a different set of config files are loaded. The files are read to string with this line;

var text = File.ReadAllText(filePath);

for example:

I have a function "LoadPatientInformationLeafletService" which requires the config be load. in the function:

 var config = SerializationService.FromJSONFile<PatientInformationLeafletConfig>("/Resources/PatientInformationLeafletConfiguration.json"); 

the FromJSONFile loads the file to string (as above), deserializes with newtonsoft and returns the PatientInformationLeafletConfig object.

The Resources dir is at the same level as the executable and is copied to the msix package at the same level.

Make sure that the Build Action of the file has been set to Content and that the COpy to Output Directory property has been set to Copy Always .

Then use an absolute path:

var config = SerializationService.FromJSONFile<PatientInformationLeafletConfig>(
    System.AppContext.BaseDirectory + "/Resources/PatientInformationLeafletConfiguration.json"); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM