Search code examples
winformsappsettingsappxmanifest

Missing file from installed app with Windows Packaging Project


Ok. Not sure where to start from.

So, A .NET Core WinForms app was packaged with a Windows Package Project but after installation of the app, it throws an exception when trying to start app, as is shown below in the image.

Missing file exception

Such file (appsettings.json) should be in installation directory as it's supposed to be copied always into the output directory when building the app, and in fact, it's being copied but I think it's something related to the Windows Packaging Project.

Not sure how to solve this issue.

Best regards!


Solution

  • I found out that it wasn't an issue related to the Windows Application Package Project. On the contrary, it was an issue when building the configuration host as it's mentioned in this stackoverflow thread:

    In .NET 6.0 or above try using:

    System.AppContext.BaseDirectory

    instead of

    Directory.GetCurrentDirectory()

    var configuration = new ConfigurationBuilder()
                            .SetBasePath(System.AppContext.BaseDirectory)
                            .AddJsonFile("appsettings.json")
    

    And that would be it! After installing the application using the WAP installer, the application will work as expected.