Best Way To Determine If .NET 3.5 Is Installed

前端 未结 9 1584
时光取名叫无心
时光取名叫无心 2021-02-05 12:43

I need to programatically determine whether .NET 3.5 is installed. I thought it would be easy:

<% Response.Write(Environment.Version.ToString()); %>


        
相关标签:
9条回答
  • 2021-02-05 13:43

    One option is to detect 4.0 using the version string:

        Environment.Version.CompareTo(new Version(4, 0));
    

    then since 2.0 and 2.5 share a CLR version number, these need to be distenguished by checking the registry. Since those versions are released already, the strings to look for are known.

    0 讨论(0)
  • 2021-02-05 13:44

    That is because technically .NET 3.5 is an extension of the 2.0 framework. The quickest way is to include an assembly from .NET 3.5 and see if it breaks.

    System.Web.Extensions
    

    Is a good assembly that is only included in version 3.5. Also it seems that you are using ASP.NET to run this check, this really limits you because you will be unable to check the file system or the registry running in the protected mode of ASP.NET. Or you can always problematically try loading an assembly from the GAC that should only be in .NET 3.5, however you may run in to problems with permissions again.

    This may be one of those times where you ask your self "What am I trying to accomplish?" and see if there are alternative routes.

    0 讨论(0)
  • 2021-02-05 13:45

    Another interesting find is the presence of assemblies here:

    C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5

    You'd think Microsoft would build a check for "latest version" into the framework.

    0 讨论(0)
提交回复
热议问题