What is the current .NET version on an Azure App Service


I have an App Service here (currentdotnetversion) that shows the output of the current (when I wrote this article) .NET version using C# code.  Here is a partial code snippet:

protected void Page_Load(object sender, EventArgs e)
{
  const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
  using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,
         RegistryView.Registry32).OpenSubKey(subkey))
  {
   if (ndpKey != null && ndpKey.GetValue("Release") != null)
   {
     LabelPublished.Text = ".NET Framework Version: " +
       $"{CheckFor45PlusVersion((int)ndpKey.GetValue("Release"))}";
   }
   else
   {
     LabelPublished.Text = ".NET Framework Version 4.5 or later is not detected.";
   }
 }
 LabelTargeted.Text = "The targeted .NET Framework version is: " +
    $"{System.Web.HttpRuntime.TargetFramework.ToString()}";
}

I took the code from here and I got the Microsoft.Win32 assembly via a NuGet package, see Figure 1.

image

Figure 1, where to get the Microsoft.Win32 assembly, how to find the .NET versions

The code basically checks for the release version in the registry, see Figure 2.  Sure you can dump it our using REG QUERY, I discuss more ways to use this command in these other articles:

image

Figure 2, How to find the .NET versions on an Azure App Service

You can also check is out in the Azure Portal on the App Service –> Application Settings blade, see Figure 3.

image

Figure 3, How to find the .NET versions on an Azure App Service

I thought about coding the same to get the version which is targeted by my ASP.NET app because it can be different than the most current version installed on the platform.  I immediately jumped to this static property, which is right:

System.Web.HttpRuntime.TargetFramework.ToString();

Then I saw that there were targetFramework attributes in 2 places within my web.config file and needed to find out which one had precedence and what this meant.

<configuration>
 <system.web>
 <compilation debug="true" targetFramework="4.7.1">
 </compilation>
 <httpRuntime targetFramework="4.7.1"/>
 </system.web>
</configuration>

I found this article very helpful “All about <httpRuntime targetFramework>” which states:

Use <httpRuntime targetFramework="#.#" /> to opt-in to new 4.5 behaviors.

Use <compilation targetFramework="#.#" /> identifies which reference assemblies are used when when performing compilation.

I interpret that to mean that use the httpRuntime which focuses your application on the 4.5 or greater version of the CLR, while compilation points the ASP.NET app to a specific version of the .NET framework.

I discuss the difference between side-by-side and in-place upgrade here “Lab 5: Basic and Advanced Application Pool Settings” which you should also understand to get the total context.  There is also a link to this article as well “.NET Versioning and Multi-Targeting - .NET 4.5 is an in-place upgrade to .NET 4.0”.

image

Comments (0)

Skip to main content