How to transform a ClickOnce winforms project from .NET Framework in VS 2019 to .NET in VS2022?

Mustang 0 Reputation points
2024-02-05T09:43:34.8033333+00:00

I have a ClickOnce winform project using .NET Framework in VS 2019 using the code from the following link: https://learn.microsoft.com/en-us/visualstudio/deployment/how-to-check-for-application-updates-programmatically-using-the-clickonce-deployment-api?view=vs-2022&tabs=csharp This works perfect including automatic updates when the application starts. How to do the same in VS 2022 with .NET? This link suggests a way forward: https://learn.microsoft.com/en-us/visualstudio/deployment/access-clickonce-deployment-properties-dotnet?view=vs-2022 However, i don't understand how. There is an example, performing the same thing as in the first link?

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,874 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,654 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Minxin Yu 11,026 Reputation points Microsoft Vendor
    2024-02-06T02:50:12.95+00:00

    Hi, @Mustang

    Use the source code: https://github.com/dotnet/deployment-tools/blob/main/Documentation/dotnet-mage/ApplicationDeployment.cs And Check version sample:

    public Boolean IsNewVersionAvailable()
    {
        Boolean isRestartRequired = false;
    
        if (ApplicationDeployment.IsNetworkDeployed)
        {
            ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
            if (ad.UpdatedVersion > ad.CurrentVersion)
            {
                isRestartRequired = true;
            }
        }
    
        return (isRestartRequired);
    }
    

    Note:
    UpdatedVersion differs from CurrentVersion if a new update has been installed but you have not yet called Restart on the Application. If the application's deployment manifest is configured to perform automatic updates, you can compare these two values to determine whether you should restart the application. If the application has not been updated, UpdatedVersion returns the same value as CurrentVersion.

    There is no CheckForUpdate() function provided, so you cannot check for undeployed updates in .NET app.

    You could follow up the GitHub related page: https://github.com/dotnet/deployment-tools/issues/27

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.