2011-02-23 8 views
6

어떻게 응용 프로그램에서 사용중인 dotnet의 버전을 C# 응용 프로그램 자체에서 확인할 수 있습니까?내 dotnet 버전 확인

+0

응용 프로그램에서 요구하는 최소 버전을 의미합니까? (프로젝트 파일의 TargetFrameworkVersion attr) –

+0

사실 현재 응용 프로그램 프레임 워크의 경로가 필요합니다. 내 응용 프로그램은 현재 실행중인 버전에서 일부 exe를 실행해야합니다. 즉, 내 응용 프로그램이 2.0을 사용하는 경우 .net 2.0 폴더에서 exe를 선택하고 4를 사용하는 경우 .net 4.0 폴더에서 exe를 선택합니다. – hungryMind

답변

12

Environment.Version을 사용하십시오. 응용 프로그램을 실행하는 .NET의 정확한 버전을 제공합니다.

공용 언어 런타임의 주 버전, 부 버전, 빌드 버전 및 수정 버전 번호를 설명하는 Version 개체를 가져옵니다.


는 프레임 워크의 버전이 설치되어 알아 this SO 질문과 답변을 참조하십시오. 너트 쉘에서 레지스트리를 파헤쳐 야합니다.

+3

3.5, 3.0 및 2.0을 구별 할 수 있습니까? (런타임은 2.0.something과 동일합니다.) – xanatos

+0

@xanatos - 아니요. 런타임 버전을 반환합니다. 설치된 것이 무엇인지 알아야 할 경우 [this] (http://stackoverflow.com/questions/199080/how-to-detect-what-net-framework-versions-and-service-packs-are-installed)를 참조하십시오. 그래서 질문과 대답. – Oded

6

당신은을 사용할 수 있습니다

Environment.Version 

는 .NET 런타임의 버전 번호를 얻을 수 있습니다.

0

콘솔 응용 프로그램이 클래스를 추가 만들고이를

은 Visual Studio에서
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가 도움이되는 방법에 대한 설명과 함께 몇 가지 설명을 추가하십시오. –

0

, 이> Nutget 패키지 관리 -> 패키지 관리자 콘솔 유형 DOTNET 에 --version 을 도구 -로 이동 실행 그리고 여기에 간다!