private static UnconfiguredProject GetUnconfiguredProject(IVsProject project) { ThreadHelper.ThrowIfNotOnUIThread(); IVsBrowseObjectContext context = project as IVsBrowseObjectContext; if (context == null) { IVsHierarchy hierarchy = project as IVsHierarchy; if (hierarchy != null) { object extObject; if (ErrorHandler.Succeeded(hierarchy.GetProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ExtObject, out extObject))) { Project dteProject = extObject as Project; if (dteProject != null) { context = dteProject.Object as IVsBrowseObjectContext; } } } } return(context != null ? context.UnconfiguredProject : null); }
private static bool TryGetProjectServices(EnvDTE.Project project, out IUnconfiguredProjectServices unconfiguredProjectServices, out IProjectServices projectServices) { IVsBrowseObjectContext context = project as IVsBrowseObjectContext; if (context == null && project != null) { // VC implements this on their DTE.Project.Object context = project.Object as IVsBrowseObjectContext; } if (context == null) { unconfiguredProjectServices = null; projectServices = null; return(false); } else { UnconfiguredProject unconfiguredProject = context.UnconfiguredProject; // VS2017 returns the interface types of the services classes but VS2019 returns the classes directly. // Hence, we need to obtain the object via reflection to avoid MissingMethodExceptions. object services = typeof(UnconfiguredProject).GetProperty("Services").GetValue(unconfiguredProject); object prjServices = typeof(IProjectService).GetProperty("Services").GetValue(unconfiguredProject.ProjectService); unconfiguredProjectServices = services as IUnconfiguredProjectServices; projectServices = prjServices as IProjectServices; return(unconfiguredProjectServices != null && project != null); } }
public static void DoWorkInWriterLock(this Project project, Action <MsBuildProject> action) { IVsBrowseObjectContext context = project.Object as IVsBrowseObjectContext; if (context == null) { IVsHierarchy hierarchy = project.ToVsHierarchy(); context = hierarchy as IVsBrowseObjectContext; } if (context != null) { var service = context.UnconfiguredProject.ProjectService.Services.DirectAccessService; if (service != null) { // This has to run on Main thread, otherwise it will dead-lock (for C++ projects at least) ThreadHelper.Generic.Invoke(() => service.Write( context.UnconfiguredProject.FullPath, dwa => { MsBuildProject buildProject = dwa.GetProject(context.UnconfiguredProject.Services.SuggestedConfiguredProject); action(buildProject); }, ProjectAccess.Read | ProjectAccess.Write) ); } } }
private static void SetDotNetCoreProjectArguments(EnvDTE.Project project, string arguments) { IVsBrowseObjectContext context = project as IVsBrowseObjectContext; if (context == null && project != null) { // VC implements this on their DTE.Project.Object context = project.Object as IVsBrowseObjectContext; } if (context != null) { var launchSettingsProvider = context.UnconfiguredProject.Services.ExportProvider.GetExportedValue <ILaunchSettingsProvider>(); var activeLaunchProfile = launchSettingsProvider.ActiveProfile; if (activeLaunchProfile == null) { return; } WritableLaunchProfile writableLaunchProfile = new WritableLaunchProfile(launchSettingsProvider.ActiveProfile); writableLaunchProfile.CommandLineArgs = arguments; launchSettingsProvider.AddOrUpdateProfileAsync(writableLaunchProfile, false); } }
public IVsProjectManager GetProjectManager(IVsProject project) { #if VS2017 IVsBrowseObjectContext context = project as IVsBrowseObjectContext; if (context == null) { var dteProject = project.GetDTEProject(); if (dteProject != null) { context = dteProject.Object as IVsBrowseObjectContext; } } if (context != null) { return(new CPSProjectManagerI(context.UnconfiguredProject)); } else { return(new MSBuildProjectManagerI(project.GetDTEProject())); } #else return(new MSBuildProjectManagerI(project.GetDTEProject())); #endif }
private void EnablePackageRestoreForJavaScriptProject(Project javaScriptProject) { IVsHierarchy hierarchy = javaScriptProject.ToVsHierarchy(); IVsBrowseObjectContext context = hierarchy as IVsBrowseObjectContext; if (context != null) { var service = context.UnconfiguredProject.ProjectService.Services.DirectAccessService; if (service != null) { service.Write( context.UnconfiguredProject.FullPath, dwa => { MsBuildProject buildProject = dwa.GetProject(context.UnconfiguredProject.Services.SuggestedConfiguredProject); // When inside the Write lock, calling Project.Save() will cause a deadlock. // Thus we will save it after and outside of the Write lock. EnablePackageRestore(javaScriptProject, buildProject, saveProjectWhenDone: false); }, ProjectAccess.Read | ProjectAccess.Write); javaScriptProject.Save(); } } }
private UnconfiguredProject GetUnconfiguredProject(EnvDTE.Project project) { IVsBrowseObjectContext context = project as IVsBrowseObjectContext; if (context == null && project != null) { // VC implements this on their DTE.Project.Object context = project.Object as IVsBrowseObjectContext; } return(context != null ? context.UnconfiguredProject : null); }
private UnconfiguredProject GetUnconfiguredProject(EnvDTE.Project project) { ThreadHelper.ThrowIfNotOnUIThread(); IVsBrowseObjectContext context = project as IVsBrowseObjectContext; if (context == null && project != null) { // VC implements this on their DTE.Project.Object context = project.Object as IVsBrowseObjectContext; } return(context?.UnconfiguredProject); }
public static UnconfiguredProject GetUnconfiguredProject(this IVsHierarchy hierarchy) { IVsBrowseObjectContext context = hierarchy as IVsBrowseObjectContext; if (context == null) { EnvDTE.Project dteProject = hierarchy.GetDTEProject(); if (dteProject != null) { context = dteProject.Object as IVsBrowseObjectContext; } } return(context?.UnconfiguredProject); }
/// <summary> /// Convenient way to get to the UnconfiguredProject from the hierarchy /// </summary> public static UnconfiguredProject GetUnconfiguredProject(this IVsHierarchy hierarchy) { VsAppShell.Current.AssertIsOnMainThread(); IVsBrowseObjectContext context = hierarchy as IVsBrowseObjectContext; if (context == null) { EnvDTE.Project dteProject = hierarchy.GetDTEProject(); if (dteProject != null) { context = dteProject.Object as IVsBrowseObjectContext; } } return(context?.UnconfiguredProject); }
public static UnconfiguredProject GetUnconfiguredProject(IVsProject project) { UnconfiguredProject unconfiguredProject = null; ThreadHelper.JoinableTaskFactory.Run(async() => { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsBrowseObjectContext context = project as IVsBrowseObjectContext; if (context == null) { var dteproject = project.GetDTEProject(); if (dteproject != null) { context = dteproject.Object as IVsBrowseObjectContext; } } unconfiguredProject = context != null ? context.UnconfiguredProject : null; }); return(unconfiguredProject); }
private UnconfiguredProject GetUnconfiguredProject(IVsProject project) { ThreadHelper.ThrowIfNotOnUIThread(); IVsBrowseObjectContext context = project as IVsBrowseObjectContext; if (context == null) { // VC implements this on their DTE.Project.Object if (project is IVsHierarchy hierarchy) { if (ErrorHandler.Succeeded(hierarchy.GetProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ExtObject, out object extObject))) { if (extObject is EnvDTE.Project dteProject) { context = dteProject.Object as IVsBrowseObjectContext; } } } } return(context?.UnconfiguredProject); }
private static async ATask SetVCProjectsConfigurationProperties12(DTEProject project, string configurationName, string platformName) { // Inspired from Nuget: https://github.com/Haacked/NuGet/blob/master/src/VisualStudio12/ProjectHelper.cs IVsBrowseObjectContext context = project.Object as IVsBrowseObjectContext; UnconfiguredProject unconfiguredProject = context.UnconfiguredProject; IProjectLockService service = unconfiguredProject.ProjectService.Services.ProjectLockService; using (ProjectWriteLockReleaser releaser = await service.WriteLockAsync()) { ProjectCollection collection = releaser.ProjectCollection; ConfigureCollection(collection, configurationName, platformName); _VCProjectCollectionLoaded = true; // The following was present in the NuGet code: it seesms unecessary, // as the lock it's release anyway after the using block (check // service.IsAnyLockHeld). Also it seemed to cause a deadlock sometimes // when switching solution configuration //await releaser.ReleaseAsync(); } }
private static void GetDotNetCoreProjectAllArguments(EnvDTE.Project project, List <string> allArgs) { IVsBrowseObjectContext context = project as IVsBrowseObjectContext; if (context == null && project != null) { // VC implements this on their DTE.Project.Object context = project.Object as IVsBrowseObjectContext; } if (context != null) { var launchSettingsProvider = context.UnconfiguredProject.Services.ExportProvider.GetExportedValue <ILaunchSettingsProvider>(); var launchProfiles = launchSettingsProvider?.CurrentSnapshot?.Profiles; if (launchProfiles == null) { return; } allArgs.AddRange(launchProfiles.Select(launchProfile => launchProfile.CommandLineArgs)); } }
public static UnconfiguredProject GetUnconfiguredProject(this IVsProject project) { IVsBrowseObjectContext context = project as IVsBrowseObjectContext; if (context == null) { // VC implements this on their DTE.Project.Object IVsHierarchy hierarchy = project as IVsHierarchy; if (hierarchy != null) { object extObject; if (ErrorHandler.Succeeded(hierarchy.GetProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ExtObject, out extObject))) { EnvDTE.Project dteProject = extObject as EnvDTE.Project; if (dteProject != null) { context = dteProject.Object as IVsBrowseObjectContext; } } } } return(context != null ? context.UnconfiguredProject : null); }