Как получить версию .NET Framework
Материал из 1GbWiki.
(Различия между версиями)
Версия 13:32, 15 июля 2009 (править) Dmach (Обсуждение | вклад) м ← К предыдущему изменению |
Текущая версия (01:53, 27 февраля 2013) (править) (отменить) Marstem (Обсуждение | вклад) м (→Ссылки по теме) |
||
(11 промежуточных версий не показаны.) | |||
Строка 1: | Строка 1: | ||
== Вот так == | == Вот так == | ||
- | + | <%<font color=blue>@</font> <font color=maroon>Import</font> <font color=red>Namespace</font><font color=blue>="System.Reflection"</font> %> | |
- | <%@ Import Namespace="System.Reflection" %> | + | <%<font color=blue>@</font> <font color=maroon>Page</font> <font color=red>Language</font><font color=blue>="C#"</font> %> |
- | <%@ Page Language="C#" %> | + | |
<% | <% | ||
- | // Unique framework assembly | + | <font color=green>// Unique framework assembly</font> |
- | string fw30assembly = "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; | + | <font color=blue>string</font> fw30assembly = <font color=maroon>"PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"</font>; |
- | string fw35assembly = "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"; | + | <font color=blue>string</font> fw35assembly = <font color=maroon>"System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"</font>; |
- | string fw35sp1assembly = "System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"; | + | <font color=blue>string</font> fw35sp1assembly = <font color=maroon>"System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"</font>; |
- | Version frameworkVersion = Environment.Version; | + | <font color=teal>Version</font> frameworkVersion = <font color=teal>Environment</font>.Version; |
- | string frameworkUpdate = ""; | + | <font color=blue>string</font> frameworkUpdate = <font color=maroon>""</font>; |
- | if (frameworkVersion.Major == 2) | + | <font color=blue>if</font> (frameworkVersion.Major == 2) |
{ | { | ||
- | try | + | <font color=blue>try</font> |
{ | { | ||
- | // try load 3.0 assembly... | + | <font color=green>// try load 3.0 assembly...</font> |
- | frameworkVersion = AssemblyName.GetAssemblyName(Assembly.Load(fw30assembly).Location).Version; | + | frameworkVersion = <font color=teal>AssemblyName</font>.GetAssemblyName(<font color=teal>Assembly</font>.Load(fw30assembly).Location).Version; |
- | // ... 3.5 | + | <font color=green>// ... 3.5</font> |
- | frameworkVersion = AssemblyName.GetAssemblyName(Assembly.Load(fw35assembly).Location).Version; | + | frameworkVersion = <font color=teal>AssemblyName</font>.GetAssemblyName(<font color=teal>Assembly</font>.Load(fw35assembly).Location).Version; |
- | // 3.5 sp1 | + | <font color=green>// ... 3.5 sp1</font> |
- | frameworkVersion = AssemblyName.GetAssemblyName(Assembly.Load(fw35sp1assembly).Location).Version; | + | frameworkVersion = <font color=teal>AssemblyName</font>.GetAssemblyName(<font color=teal>Assembly</font>.Load(fw35sp1assembly).Location).Version; |
- | frameworkUpdate = "SP1"; | + | frameworkUpdate = <font color=maroon>"SP1"</font>; |
} | } | ||
- | catch | + | <font color=blue>catch</font> |
{ | { | ||
- | // Assembly load filed | + | <font color=green>// Assembly load filed</font> |
} | } | ||
} | } | ||
- | string ver = string.Format(".NET Framework version is {0}.{1} {2}", | + | <font color=blue>string</font> ver = <font color=blue>string</font>.Format(<font color=maroon>".NET Framework version is {0}.{1} {2}"</font>, |
frameworkVersion.Major, | frameworkVersion.Major, | ||
frameworkVersion.Minor, | frameworkVersion.Minor, | ||
frameworkUpdate); | frameworkUpdate); | ||
- | Response.Write(ver); | + | <font color=teal>Response</font>.Write(ver); |
%> | %> | ||
- | [[ | + | == Ссылки по теме == |
- | [[Категория: | + | |
+ | * [http://www.dmach.ru/fwver.aspx http://www.dmach.ru/fwver.aspx - пример работы] | ||
+ | * [http://tomilin.livejournal.com/1277850.html Упоминания в СМИ] | ||
+ | * [http://stackoverflow.com/questions/16178/best-way-to-determine-if-net-3-5-is-installed/ stackoverflow.com - коллективный разум] | ||
+ | |||
+ | [[Категория:WEB-сервер IIS]] | ||
[[Категория:ASP.NET]] | [[Категория:ASP.NET]] | ||
- | [[Категория:Windows]] |
Текущая версия
[править] Вот так
<%@ Import Namespace="System.Reflection" %> <%@ Page Language="C#" %> <% // Unique framework assembly string fw30assembly = "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; string fw35assembly = "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"; string fw35sp1assembly = "System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"; Version frameworkVersion = Environment.Version; string frameworkUpdate = ""; if (frameworkVersion.Major == 2) { try { // try load 3.0 assembly... frameworkVersion = AssemblyName.GetAssemblyName(Assembly.Load(fw30assembly).Location).Version; // ... 3.5 frameworkVersion = AssemblyName.GetAssemblyName(Assembly.Load(fw35assembly).Location).Version; // ... 3.5 sp1 frameworkVersion = AssemblyName.GetAssemblyName(Assembly.Load(fw35sp1assembly).Location).Version; frameworkUpdate = "SP1"; } catch { // Assembly load filed } } string ver = string.Format(".NET Framework version is {0}.{1} {2}", frameworkVersion.Major, frameworkVersion.Minor, frameworkUpdate); Response.Write(ver); %>