.NET MSIX config file location

Copper Contributor

I'm using MSIX packaging in .NET 5 WPF.

I'm also using a generic host, so I build the config file via IConfigurationBuilder.

 

When debugging without MSIX, there is no problem when I make my settings file as appsettings.json file name and use it as shown in the screenshotWhen debugging without MSIX, there is no problem when I make my settings file as appsettings.json file name and use it as shown in the screenshotHowever, when starting debugging in MSIX format, the configuration file is not copied to my application path.However, when starting debugging in MSIX format, the configuration file is not copied to my application path.

 

Where are my config files copied to on MSIX?

The build action of my appsettings.json file is 'content' and always copy.

 

----

When debugging in .NET project debug mode, the path to HostBuilderContext.HostingEnvironment.ContentRootPath will be in the debug folder in the normal project subpath.

But when I debug in MSIX project debug mode, the path to HostBuilderContext.HostingEnvironment.ContentRootPath is C:\Windows\SysWoW64 .

Why does MSIX have different paths?

 

 

1 Reply
I found the answer.

On MSIX, HostBuilderContext.HostingEnvironment.ContentRootPath behaves differently.

I solved it by replacing System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) with this