Giter Club home page Giter Club logo

autoupdateprojectsminimumrequiredclickonceversion's Introduction

๐Ÿ’ฌ Project Description

Automatically force your ClickOnce app to update itself without prompting the user; this is less obtrusive to the user experience when receiving updates, and enhances security by ensuring the latest version is always used.

This is a PowerShell script that updates the ClickOnce application's minimum required version to the latest published version. This will eliminate the prompt that asks the user if they want to download and install the latest version; instead the update will automatically be downloaded and installed.

๐Ÿ’ฟ Installation

The installation instructions below are intended to be used when publishing your ClickOnce app from Visual Studio. If you are looking to publish your ClickOnce app from a CI/CD pipeline, check out this blog post.

.NET Framework Project and Packages.config Installation

If you are using a .NET Framework project, as well as the packages.config package management format, simply install the AutoUpdateProjectsMinimumRequiredClickOnceVersion NuGet package to your project, and it will automatically handle all of the installation for you.

NOTE: If you are using the PackageReference NuGet package management format, you will need to follow the manual installation instructions in the following section below.

Navigate to Manage NuGet Packages Install package window File added to project

As you can see in the last screenshot above, the NuGet package will add a PostBuildScripts folder to your project that contains the AutoUpdateProjectsMinimumRequiredClickOnceVersion.ps1 PowerShell script that is ran after each build. It also update's the project file to add a post-build event to run the PowerShell script.

.NET Core Project / PackageReference Installation (e.g. .NET Core 3.1, .NET 5, .NET 6, etc.)

.NET Core projects use the PackageReference NuGet package management format, where NuGet package references are stored directly in the project file instead of a separate packages.config file. Unfortunately the PackageReference format does not support NuGet packages running scripts during installation, so it cannot automatically add the required post-build event to the project.

Instead of using the NuGet package, you will instead need to manually add the PowerShell script to your project, and add the post-build event to the project file. The steps to do this are:

  1. In Visual Studio, right-click on your project and add a new folder called PostBuildEvents.

  2. Download the latest AutoUpdateProjectsMinimumRequiredClickOnceVersion.ps1 PowerShell script and save it to the PostBuildEvents folder.

  3. You should now see the PowerShell script in the PostBuildEvents folder in Solution Explorer.

    1. If you do not see the PowerShell file in Visual Studio, right-click on the PostBuildEvents folder and choose Add > Existing Item.... Select the PowerShell script that you downloaded and saved to the PostBuildEvents folder.
  4. In Visual Studio, right-click on the project and choose Properties.

  5. Navigate to the Build > Events tab, and paste the following code into the Post-build event text box:

    REM Update the ClickOnce MinimumRequiredVersion so that it auto-updates without prompting.
    PowerShell -ExecutionPolicy Bypass -Command "& '$(ProjectDir)PostBuildScripts\AutoUpdateProjectsMinimumRequiredClickOnceVersion.ps1' -ProjectFilePaths '$(ProjectPath)'"

The end result should look like this:

Add PowerShell file to project and add post-build event

If you have multiple projects that you deploy via ClickOnce, you'll want to do the steps above for each project.

โš’ Additional ClickOnce Setup

After the installation, if you haven't published your ClickOnce app yet, when you build your project it may fail with an error like:

MSB3073 PowerShell script exited with code 1.

If you check the Output pane in Visual Studio, it may mention that your project does not have any ClickOnce deployment settings in it. Before the build will succeed, you need to configure those settings.

.NET Framework Project ClickOnce Settings

.NET Framework projects store their ClickOnce settings in the project file. To configure the settings:

  1. You can access the project settings by right-clicking the project in Visual Studio and choosing Properties.

  2. In the project properties, on the Publish tab, in the Updates... button, make sure the following options are checked:

    1. The application should check for updates
    2. Specify a minimum required version for this application

    Set projects ClickOnce settings

.NET Core Project ClickOnce Settings

.NET Core projects store their ClickOnce settings in a publish profile xml file. To configure the settings:

  1. You can edit the publish profile settings by right-clicking the project in Visual Studio and choosing Publish... to get to the wizard.

  2. If you have multiple publish profiles, choose the appropriate ClickOnce profile, or create a new one.

  3. In the Publish wizard, within the Settings tab, make sure the following options are checked:

    1. The application should check for updates
    2. In the Update Settings window, Specify a minimum required version for this application

    Set .NET Core publish profiles ClickOnce settings

๐Ÿค” Troubleshooting

If for some reason the script is not updating your project's MinimumRequiredVersion to the latest published version, check the Visual Studio Output window for error messages thrown by the PowerShell script.

๐Ÿ“ƒ Manually Running The PowerShell Script

Detailed help documentation for manually running the PowerShell script can be obtained by running the Get-Help cmdlet against the script in a PowerShell window.

For example, open up a Windows PowerShell command prompt, navigate to the folder containing the AutoUpdateProjectsMinimumRequiredClickOnceVersion.ps1 script, and enter:

Get-Help .\AutoUpdateProjectsMinimumRequiredClickOnceVersion.ps1 -Detailed

๐Ÿ˜Ž Tips

The first build after each ClickOnce deployment will update the .csproj file, and the project will need to be reloaded. If you are running an older version of Visual Studio (2012 or earlier), to prevent the reloading of the project from closing any tabs that you have open I recommend installing the Workspace Reloader Visual Studio extension.

๐Ÿ’ณ Donate

Buy me a hot chocolate for providing this project open source and for free ๐Ÿ™‚

paypal

autoupdateprojectsminimumrequiredclickonceversion's People

Contributors

deadlydog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

autoupdateprojectsminimumrequiredclickonceversion's Issues

Add support for pubxml files

Would it be possible to add support for the new .net Core csproj files and .pubxml publish files?
I'd like to use this tool, but it only recognizes publish rules if they are embedded in the project file. That is not the standard behavior, publish profiles are now stored in standalone files

The publish profile files can be found here: $(ProjectDir)Properties\PublishProfiles\

The target extension is .pubxml

To identify ClickOnce publish profiles look for this tag in the pubxml file: <PublishProtocol>ClickOnce</PublishProtocol>. This identifies the profile as a ClickOnce as opposed to folder or Docker profiles

Additionally, it would be very nice for the publish profile to get its version numbers from the csproj file
Example:

  • Publish profile versions:
    • <ApplicationVersion>0.1.0.0</ApplicationVersion>
    • <MinimumRequiredVersion>0.1.0.0</MinimumRequiredVersion>
  • csproj version
    • <Version>0.1.1.0</Version>

I want to be able to set csproj.Version and have both of the publish profile versions update as well

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.