Get the default project directory in the Visual Studio 2010 extension

How to get the default project creation directory from the Visual Studio 2010 extension? By default, this directory:

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

I assume that this is done through the Tools-> Options window, but I do not know how to do this through the SDK.

At first glance, it looks like this: I need to close:

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

But I get the following error:

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

Found:
http://msdn.microsoft.com/en-us/library/ms165642.aspx

After Visual Studio starts once, the property element names for the current Visual Studio instance are stored in the following Windows registry key: HKCU \ SOFTWARE \ Microsoft \ VisualStudio \ 10.0_Config \ AutomationProperties. This place always has a final list of names. Category names are the names of the AutomationProperties key subkeys (Database Tools, FontsAndColors, etc.). Page names are the names of section keys for categories. For example, the FontsAndColors category contains Dialogs and Tool Windows, Printer, and TextEditor pages. You can view the registry using the registry editor.

And here is the code to get the values ​​I'm looking for:

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

Please note that the values ​​in the registry do not match what you see in Visual Studio, so a little detective work is required to get the exact value you are looking for. I assume it is configured this way due to backward compatibility.

+7
source

All Articles