Frustrations and Complexities of Updating appsettings.json During Installation #7851
Replies: 5 comments 13 replies
-
I've come up with a workaround and .... lets just say I don't think this is Rob approved.
and the wxs:
I'd love to know if anyone else has a better solution. |
Beta Was this translation helpful? Give feedback.
-
I didn't read everything you wrote but I know how I dealt with this in .NET framework. It's much simpler and I'm sure if you reframe the problem you can think of a way to do it in .NET. I haven't really bothered to do it yet because most of my .NET apps are in house server apps where I can just bake the settings into a file for each life cycle. So in App.Config there was a file attribute on the AppSettings element that specified a relative path file that contained override files. You could have: foo.exe.config -> foo.exe.config.override This solved the merge dilema by keeping built/static installer owned data in one file (foo.exe.config) and configuration data or user provided data in a seperate file (foo.exe.config.override) My doing this MSI could always safely overwrite the first file and would never touch the second file because it didn't create it or know about it unless done by custom action in which case you owned the data following the remember property pattern. I've used this countless times and it works perfectly. |
Beta Was this translation helpful? Give feedback.
-
Here, let me give a more realistic hypothetical example to provide more context Old Config:
New Config:
Resulting Config after update:
|
Beta Was this translation helpful? Give feedback.
-
I've already handled that in code not listed here:
I agree and I'm still looking into this. |
Beta Was this translation helpful? Give feedback.
-
Since your JSON has "theme" I'm going to assume it's got a UI which means you can have code on first run. Installler installs INSTALLLOCATION\default.json with contents: { Your application code has first run that decides which of these should be sticky and which will be allowed to float. It creates C:\ProgramData...\machine-wide-override.json and/or populates the values that are sticky and don't already exist. You upgrade your application and you simply replace INSTALLLOCATION\default.json with the newest version in the build. Your application code has first run that once again decides which should be sticky and which will be allowed to float. It updates machine-wide-override.json with any additional settings that are sticky that don't yet exist in machine-wide-override.json. Now you have no custom actions in the installer and your business logic is written in .net where you are more easily able to manage it. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello WiX Community,
I’ve come across a significant challenge while trying to perform what seems like it should be a simple task: updating an appsettings.json file during the installation of a .NET application. The goal is to merge settings from an old configuration file with a new one during the upgrade process, retaining only the settings from the old existing config while adding any potentially new configurations in the new version.
The issue arises when attempting to execute this code within a deferred custom action:
Despite configuring my deferred custom action to run after InstallFiles—which should ensure that the appsettings.json is in place—the custom action is unable to locate the file in the INSTALLFOLDER. The file's absence is unexpected since the installer should have already copied it to the destination directory. This behavior occurs during upgrade sequences, where the action's purpose is to merge the existing settings with the new ones, crucial for the application's functionality.
Here's the relevant section from my WiX setup:
The core issue is that even though the UpdateAppSettings custom action is scheduled correctly and the INSTALLFOLDER property is set, the file does not appear to be accessible or present at the time the custom action executes. This is contrary to what one would expect given the sequence specified in the WiX script.
I’ve been through numerous posts and documentation, tried various combinations of deferred and immediate custom actions, and encountered every roadblock you can imagine, not to mention the countless hours I've spent watching all of the youtube videos from the deployment dojo – from permission issues to the notorious "file not found" errors because the files are still in their temporary state.
I’m aware of the philosophical stance in the WiX community that custom actions are generally a sign of installation failure, or at best, a necessary evil. While I understand the sentiment behind minimizing the use of custom actions, as highlighted in Rob Mensching's blog post "Zataoca: Custom actions are (generally) an admission of failure," I find myself at an impasse.
Adding to the confusion is the state of the official WiX documentation. The current resources seem to offer a fragmented view—focusing on isolated details without much-needed context or comprehensive coverage. This absence of structured and thorough documentation leaves developers piecing together information like a jigsaw puzzle, often having to resort to trial and error to understand the full picture of how WiX operates, particularly with complex custom actions.
The disorganized state of the documentation has only amplified the difficulties I've encountered with this installation procedure. A process that should be straightforward is now mired in opacity, leading to an excessive amount of time spent on what should be a routine task.
Here are the options as I see them:
Wait for a solution to be implemented in some library, delaying the project indefinitely.
Attempt a workaround that might involve less-than-ideal practices and potential future headaches.
Continue to pour hours into finding a solution that allows the custom action to execute as intended.
The frustration stems from the necessity of the task at hand. We're not discussing a frivolous or optional feature – this is a core functionality that needs to be addressed for the application to work correctly post-upgrade. I urge the WiX team to consider enhancing the documentation to provide a clearer, more sequential guide that walks through the process, especially for deferred custom actions.
To the experts and veterans here: what is the recommended course of action when faced with such a scenario? Is there a middle ground where practicality meets best practice? And how do we reconcile the need to deliver on time with the desire to adhere to the principles of good setup design?
I’m reaching out to the community in hopes of finding guidance, or perhaps to spark a discussion on how we can better handle these types of common tasks within the WiX framework.
Thank you for your time and assistance.
Beta Was this translation helpful? Give feedback.
All reactions