p.s.w.g
p.s.w.g

Reputation: 148990

.NET Framework 4.0.3 as a Prerequisite in ClickOnce package

I have an application that targets .NET 4.0 packaged as a ClickOnce deployment—built with VS 2015 Enterprise. It will install just fine with only 4.0 installed, but in testing I've found that the application requires update 4.0.3 (KB2600211) in order to work correctly.

How do I make this update a prerequisite for installing the software? It doesn't appear to be an option: Prerequisites

Upvotes: 0

Views: 1186

Answers (1)

p.s.w.g
p.s.w.g

Reputation: 148990

At this time I haven't really found a solution, but I've come up with this rather kludgy workaround. Basically, I found the section of app startup code that throws an error on systems that don't have this update, and wrapped it in special error handling code. In that error handler, I simply do a manual check on the current runtime version and if it fails, I present the user with a specific error message.

private static string InvalidFxVerMessage = 
    "This application requires .NET Framework v{0} or later but has detected that your system is running v{1}.\n\n" +
    "Please contact your system administrator to install the following components: \n" +
    "\u2003\u2022 Update 4.0.3 for Microsoft .NET Framework 4 – Runtime Update (KB2600211)"

private void InitializeApp()
{
    try
    {
        // Run some code that throws an exception if update 4.0.3 is not installed.
    }
    catch (Exception)
    {
        var envVers = Environment.Version;
        var reqVers = new Version(4, 0, 30319, 551);
        if (envVers < reqVers)
        {
            var msg = string.Format(InvalidFxVerMessage, reqVers, envVers);
            MessageBox.Show(
                msg,
                "Unsupported Framework Version",
                MessageBoxButton.OK,
                MessageBoxImage.Error);
            Environment.Exit(0);
        }

        throw;
    }
}

It's not great and I'd love to find a better solution, but this at least tells the user exactly what went wrong and gives them an indication of how to fix it.

Upvotes: 1

Related Questions