如何从c#应用程序本身检查应用程序正在使用哪个dotnet版本?确定我的dotnet版本
6
A
回答
12
使用Environment.Version
- 它为您提供运行应用程序的.NET的确切版本。
获取版本对象,该对象描述公共语言运行库的主要版本,次要版本,生成版本和修订版本号。
要找出安装的是什么版本的框架,见this SO问题和答案。在坚果外壳中,您将需要深入注册表。
6
您可以使用:
Environment.Version
获得.NET运行时的版本号。
0
创建控制台应用程序添加这个类并运行它
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
public class GetDotNetVersion
{
public static void Get45PlusFromRegistry()
{
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)
{
Console.WriteLine(".NET Framework Version: " + CheckFor45PlusVersion((int)ndpKey.GetValue("Release")));
}
else
{
Console.WriteLine(".NET Framework Version 4.5 or later is not detected.");
}
}
}
// Checking the version using >= will enable forward compatibility.
private static string CheckFor45PlusVersion(int releaseKey)
{
if (releaseKey >= 394802)
return "4.6.2 or later";
if (releaseKey >= 394254)
{
return "4.6.1";
}
if (releaseKey >= 393295)
{
return "4.6";
}
if ((releaseKey >= 379893))
{
return "4.5.2";
}
if ((releaseKey >= 378675))
{
return "4.5.1";
}
if ((releaseKey >= 378389))
{
return "4.5";
}
// This code should never execute.
// that 4.5 or later is installed.
return "No 4.5 or later version detected";
}
}
// Calling the GetDotNetVersion.Get45PlusFromRegistry method produces
// output like the following:
// .NET Framework Version: 4.6.1
}
+0
添加一些解释与答案如何这个答案帮助OP在解决当前问题 – 2016-10-07 08:58:15
0
在你的Visual Studio, 转到工具> Nutget包管理 - >软件包管理器控制台 键入DOTNET --version 在这里你走了!
相关问题
- 1. 确定Android版本
- 2. 确定库版本?
- 3. 安装exe文件版本的dotnet
- 4. 我应该在我的Gemfile中指定确切的版本吗?
- 5. dotNet 2.0支持哪些WSDL版本?
- 6. 确定Oracle Warehouse Builder版本
- 7. 确定从PHP版本
- 8. 从java确定linux版本
- 9. 如何确定cefsharp版本
- 10. 如何确定LLVM版本?
- 11. 确定Redhat Linux版本
- 12. 确定组件版本
- 13. 确定特定软件包的版本
- 14. 如何正确确定版本号?
- 15. DOTNET的版本的Windows脚本宿主的
- 16. 确定Mac上的Java SDK的版本
- 17. 如何确定Android版本的版本号?
- 18. 我的RVM ruby版本不正确?
- 19. 如何确定我的应用程序支持的Android版本
- 20. 如何确定我的WebLogic Server的ojdbc驱动程序版本
- 21. 确定哪些Rails的使用Railties当我使用的版本
- 22. 确定我正在使用的实体框架的版本?
- 23. 确定易于安装的python版本
- 24. 确定当前的Angular 2.x版本
- 25. 使用java确定Microsoft Office的版本
- 26. 使用perl确定Microsoft Windows的版本?
- 27. 如何确定Makefile中的python版本?
- 28. 确定最低要求的PHP版本
- 29. UDK - 确定UE3项目的版本是
- 30. 如何确定org.netbeans.swing.outline的maven版本?
您的意思是应用程序所需的最小版本? (项目文件中的TargetFrameworkVersion属性) – 2011-02-23 10:49:00
其实我需要当前应用程序框架的路径。我的应用程序需要从当前运行的版本执行一些exe。即如果我的应用程序使用2.0,它将从.net 2.0文件夹中选择exe,如果使用4,它将从.net 4.0文件夹中选择exe。 – hungryMind 2011-02-23 12:17:35