How do I get the default project creation directory from within a Visual Studio 2010 extension? By default this directory is:
C:\Users\<username>\Documents\Visual Studio 2010\Projects
I'm guessing this is done via the Tools->Options window, but I don't know how to get at this via the SDK.
At first glance the following looks like it should get me 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))
Found it:
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.
And here's the code to get the values I'm looking for:
string defaultProjectPath = (string)(DTE.Properties("Environment", "ProjectsAndSolution").Item["ProjectsLocation"].Value);
Note that the values in the registry don't match up with what you see in Visual Studio so a little detective work is required to get to the exact value that you're looking for. I assume that it's setup this way due to backward compatibility.
User contributions licensed under CC BY-SA 3.0