Is there a way to execute code (C# preferably) either during or after ClickOnce deployment of a WPF application?

I simply want to write the new version number of the application being deployed to a database.

Bonus: Is there a way to bundle this deployment code into the project / solution so that it follows the application around to each developer?

I tried Googling but honestly haven't found any relevant threads on this topic yet.

I do notice there's "Build Events" in the project properties, but I don't know if they support C# code, and I'm more-so looking for "Deployment Events" if that's even a thing?

Not sure where to start. :(

I expect a dedicated table in my database to be updated as a result of ClickOnce deployment, hopefully via C# code. (I know how to write to a database in C#, but not sure how to execute deployment events with C# code if possible?)

2 Answers

Tejas Parnerkar On

I'm not sure which CI/CD tool you're using. But tools like Octopus and MS Build allow you to run powershell scripts as a part of your deployment pipeline.

Maybe you can execute a powershell script as a part of your deployment process to increment your version number. Here is a link to do connection to SQL server via powershell.

J.D. On

I realized sometimes asking Google the right question will yield the sought after answer.

So the problem I was trying to solve is actually simpler than my initial question, which is really that I want to periodically and programmatically check for updates within my WPF applications.

I didn't realize Microsoft offered a built in solution to this: How to: Check for application updates programmatically using the ClickOnce deployment API

It's actually quite simple too! :)