public static IVsHierarchy ToVsHierarchy(this EnvDTE.Project project) { ThreadHelper.ThrowIfNotOnUIThread(); IVsHierarchy hierarchy; // Get the vs solution var solution = ServiceLocator.GetInstance <IVsSolution>(); int hr = solution.GetProjectOfUniqueName(project.GetUniqueName(), out hierarchy); if (hr != VSConstants.S_OK) { Marshal.ThrowExceptionForHR(hr); } return(hierarchy); }
public static async Task <IVsHierarchy> ToVsHierarchyAsync(this EnvDTE.Project project) { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsHierarchy hierarchy; // Get the vs solution var solution = await ServiceLocator.GetInstanceAsync <IVsSolution>(); int hr = solution.GetProjectOfUniqueName(project.GetUniqueName(), out hierarchy); if (hr != VSConstants.S_OK) { Marshal.ThrowExceptionForHR(hr); } return(hierarchy); }
/// <summary> /// Factory method initializing instance of <see cref="ProjectNames"/> with values retrieved from a DTE project. /// </summary> /// <param name="dteProject">DTE project to get project names for.</param> /// <returns>New instance of <see cref="ProjectNames"/>.</returns> public static async Task <ProjectNames> FromDTEProjectAsync(EnvDTE.Project dteProject, SVsSolution vsSolution) { Assumes.Present(dteProject); await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); string fullname = dteProject.FullName; string uniqueName = dteProject.GetUniqueName(); string shortName = dteProject.GetName(); string customUniqueName = await dteProject.GetCustomUniqueNameAsync(); string projectId = GetProjectGuid(dteProject, vsSolution); return(new ProjectNames( fullName: fullname, uniqueName: uniqueName, shortName: shortName, customUniqueName: customUniqueName, projectId: projectId)); }