.NET Framework 디렉터리 경로 가져 오기
내 C # 응용 프로그램 내에서 .NET Framework 디렉터리 경로를 얻으려면 어떻게해야합니까?
내가 참조하는 폴더는 "C : \ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727"입니다.
현재 .NET 응용 프로그램에 대해 활성화 된 CLR의 설치 디렉터리 경로는 다음 방법을 사용하여 얻을 수 있습니다.
System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()
나는 것 강하게 레지스트리를 직접 읽기에 대한 조언. 예를 들어 .NET 응용 프로그램이 64 비트 시스템에서 실행중인 경우 CLR은 "C : \ Windows \ Microsoft.NET \ Framework64 \ v2.0.50727"(AnyCPU, x64 컴파일 대상) 또는 "C : \에서로드 할 수 있습니다. Windows \ Microsoft.NET \ Framework \ v2.0.50727 "(x86 컴파일 대상). 레지스트리를 읽어도 현재 CLR에서 사용 된 두 디렉터리 중 하나를 알 수 없습니다 .
또 다른 중요한 사실은 "현재 CLR"이 .NET 2.0, .NET 3.0 및 .NET 3.5 응용 프로그램의 경우 "2.0"이라는 것입니다. 즉, GetRuntimeDirectory () 호출은 .NET 3.5 응용 프로그램 (3.5 디렉터리에서 일부 어셈블리를로드하는) 내에서도 2.0 디렉터리를 반환합니다. ".NET Framework 디렉터리 경로"라는 용어의 해석에 따라 GetRuntimeDirectory가 찾고있는 정보가 아닐 수 있습니다 ( "CLR 디렉터리"대 "3.5 어셈블리가 나오는 디렉터리").
더 쉬운 방법은 Microsoft.Build.Utilities 어셈블리를 포함하고
using Microsoft.Build.Utilities;
ToolLocationHelper.GetPathToDotNetFramework(
TargetDotNetFrameworkVersion.VersionLatest);
Windows 레지스트리에서 가져올 수 있습니다.
using System;
using Microsoft.Win32;
// ...
public static string GetFrameworkDirectory()
{
// This is the location of the .Net Framework Registry Key
string framworkRegPath = @"Software\Microsoft\.NetFramework";
// Get a non-writable key from the registry
RegistryKey netFramework = Registry.LocalMachine.OpenSubKey(framworkRegPath, false);
// Retrieve the install root path for the framework
string installRoot = netFramework.GetValue("InstallRoot").ToString();
// Retrieve the version of the framework executing this program
string version = string.Format(@"v{0}.{1}.{2}\",
Environment.Version.Major,
Environment.Version.Minor,
Environment.Version.Build);
// Return the path of the framework
return System.IO.Path.Combine(installRoot, version);
}
[HKLM] \ Software \ Microsoft.NetFramework \ InstallRoot 키 값 읽기 - "C : \ WINDOWS \ Microsoft.NET \ Framework"가 표시됩니다. 그런 다음 원하는 프레임 워크 버전을 추가합니다.
참고 URL : https://stackoverflow.com/questions/375860/getting-the-net-framework-directory-path
'programing tip' 카테고리의 다른 글
Lisp 커뮤니티가 왜 그렇게 분열되어 있습니까? (0) | 2020.11.03 |
---|---|
오류를 제공하는 Windows의 pip-알 수 없거나 지원되지 않는 명령 'install' (0) | 2020.11.03 |
하위 디렉토리에 git 저장소 병합 (0) | 2020.11.02 |
Git Bash와 Windows 용 GitHub 쉘의 차이점은 무엇입니까? (0) | 2020.11.02 |
푸시는 새로운 원격 헤드를 만듭니다! (0) | 2020.11.02 |