r/dotnet • • 4d ago

Question Windows Installer Implementation

I'm working on an installer for an enterprise application, and our customer has requested a rollback feature that allows downgrading to a previous version while restoring the corresponding version's user data (stored in a database and designated XML configuration files).

One approach we've considered is backing up the existing database and XML files before installation, uninstalling the current version, reinstalling the previous version, and restoring the data based on version matching from a designated backup directory.

However, this relies heavily on custom scripting. In particular, I'm concerned about the reliability and atomicity of moving and restoring backup folders, as these operations introduce additional points of failure.

Another limitation is that native MSI rollback only handles failures during installation; it doesn't provide rollback after a successful installation.

Are there more reliable /established approaches to implementing version downgrades/revert while preserving previous user data?

10 Upvotes

14 comments sorted by

10

u/sereikis 4d ago

first distinguish reverting the binaries from restoring old data: restoring the pre-upgrade backup discards writes made since the upgrade. for the restore case, stop all writers, capture the database and XML as one consistent recovery set with schema/app versions, restore into staging and validate before switching over; journal each step so recovery can resume after a crash, and test that path with fault injection.

3

u/Queasy-Neck-5814 4d ago

Split it in two: reverting the installed bits and restoring user data. They need different answers.

I add new schema fields in a release where the old binary can still read the table, move the data in the next one, and only then drop the old shape. That ordering is what makes a downgrade survivable. Restoring a pre-upgrade database dump is the blunt option, and it discards every write made since the upgrade. Most of the time the old version can read the newer schema with a compatibility view instead.

Write a version marker at each step so an interrupted downgrade resumes instead of guessing. Test the interruption, not just the clean run.

2

u/--TYGER-- 3d ago

NSIS beats everything else IMO for simplicity and custom capability

1

u/AutoModerator 4d ago

Thanks for your post Tiny_Pattern_6386. Please note that we don't allow spam, and we ask that you follow the rules available in the sidebar. We have a lot of commonly asked questions so if this post gets removed, please do a search and see if it's already been asked.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/EnfieldAsSomeone 4d ago

Do you use any orm? Or is it raw sql? Orm usually provide migration ootb. If not you can use or write a migration logic (up and down) in your app and installer trigger that, subprocess, signal, or cli args doesn't matter, but ensure permission matches, like if installed as admin, only allow admin etc. data should be safe. And plan your schema changes to fit this too.

Btw Windows expose an API/regkey to trigger customize install alongside uninstall. You may have seen that a few times in action in the program list in settings/control panel. Use that to open your installer with the rollback flow.

1

u/rbobby 3d ago

Ooof... rollback to previous install all based on MSI/Windows installer... very challenging.

The general approach to an upgrade by MSI is for the msi to initiate an uninstall of the previous version and then the new version install proceeds. This makes for challenges if you need some files/information preserved across runs. If your prior version does not do this already then a new upgrade process will have challenges. Also MSI says it can leave certain indicated files behind... but I could never get that working (via WIX... probably my issue... but be warned).

An MSI can contain an optional rollback set of instructions, one for install and one for uninstall (yes an uninstall that fails can be rolled back). The install rollback occurs when the installer encounters a problem. The uninstall rollback occurs when uninstall encounters a problem.

When I had to do this I got my uninstall sequence (invoked during an upgrade's install) to specifically leave behind a copy of key files. Don't recall how... it was a pain though. Never even tried to make an automatic reinstall of the old version when the new version fails to install... too tough for me.

The core flaw to my approach was likely doing too much in the installer. It created a website and a database and installed the app... it really should have just installed the app and made local configuration a first step when running the application (i.e. redesign the entire install... hah... not today).

Good luck.

1

u/The_MAZZTer 3d ago edited 3d ago

Focus on keeping the solution as simple and flexible as possible (remember older/newer versions may add or remove files used to store user data). Personally I would just set up a solution to backup the app and data folders at install time and drop them somewhere, preferably somewhere the customer already has automated backups working.

Then a restore solution wipes (after backup, I suppose) the app and user data folders and drops a copy of the old ones back in.

Alternatively you can make every version install to a separate folder and function as a separate install (maybe going as far as separate start menu shortcuts, though that is probably too confusing and a step too much). Have the new version copy user data from the next oldest version on first run but otherwise they don't interact or interfere with each other.

Also be sure customer expectations make sense. Do they expect to be able to take new data back to an old version of the app? Probably not reasonable, they should expect data to roll back as well.

Also do they want to be able to roll back to ANY version, or just to undo a single update if they encounter a problem and want to quickly recover and get back to work? The latter will be much easier to implement. Keep a single backup that gets updated with each new version install.

1

u/dodexahedron 3d ago edited 3d ago

Appx/msix and publish it to a local winget feed.

But since it is a network-dependent application, things can get messy and you need to be careful to either make the client and server version-aware so they can fail gracefully on incompatible versions or else only retain versions that are compatible with each other, and stick to a meaningful versioning strategy to make it clear, like SemVer.

Or both.

And have a clear version support policy, and don't let them strong-arm you into an unreasonable one unless they are willing to pay extra for that.

Also.... How much rollback do they want to be able to do, and why do they want to be able to do it?
It may be an XY problem on their part, at least partially.

1

u/mertsabinov 3d ago

if you're using wix, AllowDowngrades="yes" on MajorUpgrade lets the old msi go straight over the new one, no uninstall step needed. then just back up the db + xml before each upgrade into a folder named by version and restore the matching one on downgrade

problem is the user loses whatever they did after the upgrade, so check if the customer is actually ok with that

1

u/mertsabinov 3d ago

i'd keep the installer dumb and let the app own the data. msi downgrades are already painful, adding db restore logic in custom actions makes it worse. back up the db + xml into a versioned folder before upgrading, then the old version can pick its matching backup on first start. way easier to test than custom actions

0

u/ReallySuperName 4d ago

I use https://velopack.io/ and its docs cover fetching the list of available versions, also the concept of having beta channels etc, I think this should cover all you needs.

0

u/rayyeter 4d ago

Maybe Innosetup?

0

u/webprofusor 4d ago

So the key here is that:
- You can't actually revert to previous user data without by definition having data loss, unless nobody has used the app since the update. That has to be fully understood.

Things to consider:
- If the users data now refers to reference data (types etc) that didn't exist before then the old version isn't going to handle them very well.
- Your data model should be flexible enough to move back a version but there's a limit to what's reasonable. JSON (or I guess XML! You did say enterprise lol) is good for this because your data can include stuff the old app doesn't understand, to some extent.
- Serialization/deserialization is where you will lose information. Loading new data into an old app and storing again will inevitably lose whatever settings changed that the app didn't have a model for.
- You can technically design a rollback process which preserves as much as possible but that can have new bugs for each version as well.

Probably the better thing to understand here is what they are trying to achieve, my guess if there is a bug in the new version they want to roll back the app to the old version. My approach would be to continue to consume the same data store where possible until the bug can be fixed.

By all means take a backup on upgrades and have some sort of written rollback procedure but don't make it too easy, otherwise it may be casually invoked for less than robust reasons.

Backups need to be primarily a customer responsibility, so they need to know what to backup before installing updates and if a rollback is required within a short period they can revert with minimal data loss, but if a decent amount of time has passed the new version will have new data and the reasonable fix is a bug fix, not a rollback.

As for tech, a standard app install has the app under Program Files and program data under `C:\Program Data\appname and installing the older version will only change what was under Program Files (including uninstalling).