visual-studio 查找安装 Visual Studio 的路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/847048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FInding the path where Visual Studio is Installed
提问by anonymous user
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 安装路径必须调用的函数是什么?
回答by mandaleeka
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.0\Setup\VS");
string vsInstallationPath = regKey.GetValue("ProductDir").ToString();
regKey.Close();
回答by Bruce Ikin
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.
所以向上走两个文件夹以到达安装路径的根目录。
回答by Khurram Aziz
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
回答by paxdiablo
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 haveVisual Studio installed.
因为否则的话,你需要知道有人运行您的程序实际上可能不具有安装Visual Studio。
If it isinstalled, you can generally find it at a known location in the registry, such as HKCR/Applications/devenv.exe/shell/edit/commandfor VS2008.
如果已安装,通常可以在注册表中的已知位置找到它,例如HKCR/Applications/devenv.exe/shell/edit/commandVS2008。
回答by NJENGAH
This is the quickest way to know the folder where VS is installed or any other program.
这是了解安装 VS 或任何其他程序的文件夹的最快方法。
Open VS code and when it is running; open the Windows Task Managerand navigate to the Details tab.
打开 VS 代码和运行时;打开Windows 任务管理器并导航到“详细信息”选项卡。
Right-click on the Code.exe application that should be running by now and choose the option to Open File Location:
右键单击现在应该运行的 Code.exe 应用程序,然后选择Open File Location选项:
Windows Task Manager> Details Tab> RIGHTCLICK Code.exe> Open File Location
Windows 任务管理器>详细信息选项卡> RIGHTCLICK Code.exe>打开文件位置


