/// <summary> /// Gets a property from the DTE. /// /// See http://msdn.microsoft.com/en-us/library/ms165643.aspx for /// a description of the parameter values. /// </summary> /// <returns> /// True if the property exists and was successfully cast to the requested type, /// otherwise false. /// </returns> internal static bool TryGetDteProperty <T> ( EnvDTE.DTE dte, string category, string page, string propertyName, out T retVal ) { ThreadHelper.ThrowIfNotOnUIThread(); retVal = default(T); if (dte == null) { return(false); } EnvDTE.Properties properties; try { properties = dte.get_Properties(category, page); } catch (COMException) { // EnvDTE.Properties.get_Properties throws this exception when // the category or page does not exist. return(false); } EnvDTE.Property property; try { property = properties.Item(propertyName); } catch (ArgumentException) { // EnvDTE.Property.Item throws this exception when the property // does not exist. return(false); } // Convert the property to the requested type try { retVal = (T)property.Value; return(true); } catch (InvalidCastException) { return(false); } }
public static string defaultProjectPath() { EnvDTE.DTE dte = getDTE(); return((string)(dte.get_Properties("Environment", "ProjectsAndSolution").Item("ProjectsLocation").Value) + "\\"); }