gpt4 book ai didi

c# - 在 Visual Studio 2010 扩展中获取默认项目目录

转载 作者:太空狗 更新时间:2023-10-30 00:43:22 24 4
gpt4 key购买 nike

如何从 Visual Studio 2010 扩展中获取默认项目创建目录?默认情况下,此目录为:

C:\Users\<username>\Documents\Visual Studio 2010\Projects

我猜这是通过“工具”->“选项”窗口完成的,但我不知道如何通过 SDK 完成此操作。

乍一看,下面的内容应该让我很接近:

DTE2 dte = CType(GetService(typeof(SDTE)), DTE2);
Object props = dte.Properties("Projects and Solutions", "General");

但是我得到以下错误:

System.Runtime.InteropServices.COMException was unhandled by user code
ErrorCode=-2147352565
Message=Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))

最佳答案

找到了:
http://msdn.microsoft.com/en-us/library/ms165642.aspx

After Visual Studio has been run once, the property item names for the current instance of Visual Studio are stored in the following Windows registry key: HKCU\SOFTWARE\Microsoft\VisualStudio\10.0_Config\AutomationProperties. This location always has the definitive list of names. The category names are the names of the subkeys of the AutomationProperties key (Database Tools, FontsAndColors, and so on). The page names are the names of the subkeys of the category keys. For example, the FontsAndColors category contains the Dialogs and Tool Windows, Printer, and TextEditor pages. You can view the registry by using the registry editor.

下面是获取我正在寻找的值的代码:

string defaultProjectPath = (string)(DTE.Properties("Environment", "ProjectsAndSolution").Item["ProjectsLocation"].Value);

请注意,注册表中的值与您在 Visual Studio 中看到的值不匹配,因此需要进行一些侦探工作才能获得您要查找的确切值。由于向后兼容,我假设它是这样设置的。

关于c# - 在 Visual Studio 2010 扩展中获取默认项目目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11387354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com