RSS

ClickOnce Application,Expired Certificates & Public Key Token PART III – Pushing .net Framework 3.5

In the last few weeks I wrote 2 articles on how to resolve ClickOnce certificate expiration issues. you can find those articles here :

  1. ClickOnce Application,Expired Certificates & Public Key Token PART I
  2. ClickOnce Application,Expired Certificates & Public Key Token PART II
    During my work on this ClickOnce update, we decided to upgrade the application to target .net framework 3.5 sp1.
    so I just set the target framework to 3.5 and set the required prerequisites (.net 3.5 SP1, and Windows Installer 3.1). and built the project and published it. and when I tried on a client machine which had .net framework 2.0, application got updated, prompted the uninstall message, and tried to launch the new ClickOnce application from the new URL, and BANG!. we get an error :
    image001
    The Error Message Says :

Unable to install or run the application. The application

requires that assembly WindowsBase Version 3.0.0.0 be

installed in the Global Assembly Cache (GAC) first.

Why is this ?, its because when we try to launch the new application URL we do this :

DeploymentUtils.AutoInstall("<Path toNewApplication.application>");
 

we request for the application manifest. and it fails to launch the application because it doesn’t have the prerequisites. and now to force the new prerequisites the application should call the setup.exe in the Web Server instead of the manifest. now the question is, what if the user already have  the .net Framework 3.5 SP1?, we don’t have to prompt the client to install them again by launching setup.exe, we just have to launch the manifest. To Serve both the above scenario we need to check if the client machine has .net framework 3.5 SP1, and depending on its availability we need to launch the manifest or the setup.exe. The existence of .net Framework can be obtained from the following registry location: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP image you can find out all the .net Frameworks installed and their service pack versions in this registry entry. Following are the locations of the main Net Frameworks:

Framework 1.1 Software\\Microsoft\\NET Framework Setup\\NDP\\v1.1.4322
Framework 2.0 Software\\Microsoft\\NET Framework Setup\\NDP\\v2.0.50727
Framework 3.0 Software\\Microsoft\\NET Framework Setup\\NDP\\v3.0\\Setup
Framework 3.5 Software\\Microsoft\\NET Framework Setup\\NDP\\v3.5

 

Now we can check if the required .net Framework is available in the client machine, and launch the application setup.exe or the manifest. to do this we need to programmatically check these registries. for this I used the attached code ( I Couldn’t find the original author, Credits goes to him/her) which I found from web and modified to avoid few bugs. you can add this code to your project and do the below check in your application to decide which file to be launched :

 
string FileToLaunch=@"/setup.exe";
if (FrameworkUtils.IsInstalled(FrameworkVersion.Fx35)

 && FrameworkUtils.GetServicePackLevel(FrameworkVersion.Fx35) == 1)
          {
            FileToLaunch = @"/<application manifest.application>";
          }
            MessageBox.Show("Your message here");
            string updateURL = DeploymentUtils.getUpdateURL();
            DeploymentUtils.UninstallMe();
            DeploymentUtils.AutoInstall("https://" + updateURL + FileToLaunch);
            Application.Exit();
 

And that’s all, now the application will launch the setup.exe if the client doesn’t have the .net Framework 3.5 and prompt for its installation, or launch the application manifest if client has the framework installed.

Now you can solve your ClickOnce issue as well as upgrade .net Framework in client machine at the same time without problem.

Download FrameworkUtils.cs

Popularity: 5% [?]

, , , ,

This post was written by:

Aneef Fashir - who has written 32 posts on Aneef.Net.

Software Engineer, Sri Lanka.

Contact the author

Leave a Reply

Follow me