1 minute read

A while ago I blogged about a powershell script I made that would automatically update your ClickOnce project file’s Minimum Required Version to the latest version of your application so that users would not be presented with the “There is an update for this application. Do you want to install it?” prompt; instead the application would just automatically download and install the update.  This is nice because it’s one less prompt the end-user has to see, and from a security standpoint it means that your users will be forced to always use the latest version of the app.

There was a bit of setup to get this to work.  You had to make sure the powershell script was in the proper directory and add a post-build event to your project.  I’m happy to announce that I’ve significantly updated the powershell script with more features and bug fixes, and you can now install it from NuGet, which will handle all of the setup for you.  So now making sure that your end-users are always using the latest version of your application is as easy as adding the AutoUpdateProjectsMinimumRequiredClickOnceVersion NuGet package to your ClickOnce project.

Manage NuGet

Install

File Added

As you can see in the last screenshot, it adds a new “PostBuildScripts” folder to your project that contains the powershell script that is ran from the project’s post-build event.

A couple caveats to note.  Because this uses PowerShell it means that it can only be ran on Windows machines (sorry Mac and Unix).  Also, because the powershell script modifies the .csproj/.vbproj file outside of Visual Studio, the first time you do a build after creating a new ClickOnce version, if you have any files from that project open you will be prompted to reload the project.  In order to prevent this from closing your open tabs, I recommend installing Scott Hanselman’s Workspace Reloader Visual Studio extension.

I’ve also created a CodePlex site to host this open source project.

I hope you find this helpful.  Feel free to leave a comment.

Comments

fenetre pvc pose

Hey, I think your blog might be having browser compatibility issues. When I look at your blog in Chrome, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, great blog!

Omid

I accomplished this simply by adding the followings to the project file:

<UpdateRequired>true</UpdateRequired> <MinimumRequiredVersion>$(ApplicationVersion)</MinimumRequiredVersion>

ApplicationVersion property should be incremented at build time for auto-update to work.

dlcarp

Omid, Do you mean these lines should be added to the app.manifest file? Also, Is the “ApplicationVersion” the same as the “Assembly Version” that appears in the “Assembly Information”? Thanks

Omid

@dlcarp No, I mean the project file (*.csproj). First enable ClickOnce, save the project and then modify the project file to have the above property values.

ApplicationVersion is different than AssemblyVersion. ApplicationVersion is used by ClickOnce. AssemblyVersion is used for assembly reference binding.

Update ApplicationVersion through your CI or some script for for auto-update to work.

Leave a Comment

Your email address will not be published. Required fields are marked *

Loading...