过滤安装Visual Studio的路径

时间:2022-12-03 10:23:48

I need help as to how I can find the path where Microsoft visual Studio is installed. I need to use that path in my program. What is the function that has to be called to get the path where Microsoft Visual Studio is installed ?

我需要帮助我如何找到安装Microsoft Visual Studio的路径。我需要在我的程序中使用该路径。为了获得安装Microsoft Visual Studio的路径,必须调用哪些函数?

4 个解决方案

#1


Depending on the app, it's probably best to ask the user, but here's some C# code that should do the trick for VS2008.

根据应用程序的不同,最好向用户询问,但这里有一些C#代码应该可以解决VS2008的问题。

RegistryKey regKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\9.0\Setup\VS");
string vsInstallationPath = regKey.GetValue("ProductDir").ToString();
regKey.Close();

#2


It is probably possible to find it by searching the registry, but as I wanted a solution for build scripts I have been using environment variables to do this.

可能通过搜索注册表找到它,但因为我想要一个构建脚本的解决方案,我一直在使用环境变量来做到这一点。

N.B. The name of the environment variable to query is version specific.

注:要查询的环境变量的名称是特定于版本的。

For VS2005 you can use VS80COMNTOOLS

对于VS2005,您可以使用VS80COMNTOOLS

For VS2008 you can use VS90COMNTOOLS

对于VS2008,您可以使用VS90COMNTOOLS

If you type SET VS90COMNTOOLS at a command prompt you should see: VS90COMNTOOLS=C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\

如果在命令提示符下键入SET VS90COMNTOOLS,您应该看到:VS90COMNTOOLS = C:\ Program Files \ Microsoft Visual Studio 9.0 \ Common7 \ Tools \

so go up two folders to get to the root of the install path.

所以上两个文件夹到达安装路径的根目录。

#3


From the registry, HKLM\Software\Microsoft\VisualStudio\9.0\InstallDir for Visual Studio 2008

从注册表,HKLM \ Software \ Microsoft \ VisualStudio \ 9.0 \ InstallDir for Visual Studio 2008

#4


Is this for an add-in of some sort for Visual Studio?

这是Visual Studio的某种加载项吗?

Because otherwise, you need to be aware that someone running your program may not actually have Visual Studio installed.

否则,您需要知道运行程序的人可能实际上没有安装Visual Studio。

If it is installed, you can generally find it at a known location in the registry, such as HKCR/Applications/devenv.exe/shell/edit/command for VS2008.

如果已安装,通常可以在注册表中的已知位置找到它,例如VS2008的HKCR / Applications / devenv.exe / shell / edit / command。

#1


Depending on the app, it's probably best to ask the user, but here's some C# code that should do the trick for VS2008.

根据应用程序的不同,最好向用户询问,但这里有一些C#代码应该可以解决VS2008的问题。

RegistryKey regKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\9.0\Setup\VS");
string vsInstallationPath = regKey.GetValue("ProductDir").ToString();
regKey.Close();

#2


It is probably possible to find it by searching the registry, but as I wanted a solution for build scripts I have been using environment variables to do this.

可能通过搜索注册表找到它,但因为我想要一个构建脚本的解决方案,我一直在使用环境变量来做到这一点。

N.B. The name of the environment variable to query is version specific.

注:要查询的环境变量的名称是特定于版本的。

For VS2005 you can use VS80COMNTOOLS

对于VS2005,您可以使用VS80COMNTOOLS

For VS2008 you can use VS90COMNTOOLS

对于VS2008,您可以使用VS90COMNTOOLS

If you type SET VS90COMNTOOLS at a command prompt you should see: VS90COMNTOOLS=C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\

如果在命令提示符下键入SET VS90COMNTOOLS,您应该看到:VS90COMNTOOLS = C:\ Program Files \ Microsoft Visual Studio 9.0 \ Common7 \ Tools \

so go up two folders to get to the root of the install path.

所以上两个文件夹到达安装路径的根目录。

#3


From the registry, HKLM\Software\Microsoft\VisualStudio\9.0\InstallDir for Visual Studio 2008

从注册表,HKLM \ Software \ Microsoft \ VisualStudio \ 9.0 \ InstallDir for Visual Studio 2008

#4


Is this for an add-in of some sort for Visual Studio?

这是Visual Studio的某种加载项吗?

Because otherwise, you need to be aware that someone running your program may not actually have Visual Studio installed.

否则,您需要知道运行程序的人可能实际上没有安装Visual Studio。

If it is installed, you can generally find it at a known location in the registry, such as HKCR/Applications/devenv.exe/shell/edit/command for VS2008.

如果已安装,通常可以在注册表中的已知位置找到它,例如VS2008的HKCR / Applications / devenv.exe / shell / edit / command。