public static void SetupGenerated(EnvDTE.Project project, String file) { List <String> generated = GetGeneratedFiles(project, file); foreach (String generatedFile in generated) { if (!Directory.Exists(Path.GetDirectoryName(generatedFile))) { Directory.CreateDirectory(Path.GetDirectoryName(generatedFile)); } if (!File.Exists(generatedFile)) { File.Create(generatedFile).Dispose(); } EnvDTE.ProjectItem item = FindProjectItem(generatedFile, project.ProjectItems); if (item == null) { if (DTEUtil.IsCppProject(project)) { String filter = KnownHeaderExtension.Contains( Path.GetExtension(generatedFile)) ? "Header Files" : "Source Files"; Package.Instance.VCUtil.AddToFilter(project, filter, generatedFile); } else { project.ProjectItems.AddFromFile(generatedFile); } } } Package.Instance.FileTracker.Add(project, file, generated); }
public static void TryUpgrade(List <IVsProject> projects) { string baseDir = string.Empty; if (!string.IsNullOrEmpty(Package.Instance.DTE2.Solution.FullName)) { baseDir = Path.GetDirectoryName(Package.Instance.DTE2.Solution.FullName); } Dictionary <string, IVsProject> upgradeProjects = new Dictionary <string, IVsProject>(); foreach (IVsProject project in projects) { if (DTEUtil.IsCppProject(project) || DTEUtil.IsCSharpProject(project)) { string fullName = ProjectUtil.GetProjectFullPath(project); if (new OldConfiguration().Load(MSBuildUtils.LoadedProject(fullName, DTEUtil.IsCppProject(project), true), false)) { upgradeProjects.Add(FileUtil.RelativePath(baseDir, fullName), project); } } } if (upgradeProjects.Count > 0) { UpgradeDialog dialog = new UpgradeDialog(); dialog.StartPosition = FormStartPosition.CenterParent; dialog.Projects = upgradeProjects; dialog.ShowDialog(); } }
private void removeIceBuilder_BeforeQueryStatus(object sender, EventArgs e) { try { OleMenuCommand command = sender as OleMenuCommand; if (command != null) { EnvDTE.Project p = DTEUtil.GetSelectedProject(); if (p != null) { if (DTEUtil.IsCppProject(p) || DTEUtil.IsCSharpProject(p)) { command.Enabled = MSBuildUtils.IsIceBuilderEnabeld(MSBuildUtils.LoadedProject(p.FullName)); } else { command.Enabled = false; } } } } catch (Exception ex) { Package.UnexpectedExceptionWarning(ex); throw; } }
public void AddIceBuilderToProject(EnvDTE.Project p) { Microsoft.Build.Evaluation.Project project = MSBuildUtils.LoadedProject(p.FullName); if (MSBuildUtils.AddIceBuilderToProject(project)) { if (DTEUtil.IsCppProject(p)) { VCUtil.SetupSliceFilter(p); } else { String includeDirectories = ProjectUtil.GetProperty(p, PropertyNames.IncludeDirectories); if (String.IsNullOrEmpty(includeDirectories)) { ProjectUtil.SetProperty(p, PropertyNames.IncludeDirectories, @"$(IceHome)\slice"); } else if (includeDirectories.IndexOf(@"$(IceHome)\slice") == -1) { ProjectUtil.SetProperty(p, PropertyNames.IncludeDirectories, String.Format(@"$(IceHome)\slice;{0}", includeDirectories)); } ProjectUtil.AddAssemblyReference(p, "Ice"); } p.Save(); IVsHierarchy hier = DTEUtil.GetIVsHierarchy(p); Guid projectGUID = Guid.Empty; IVsSolution.GetGuidOfProject(hier, out projectGUID); IVsSolution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, hier, 0); project.Save(); IVsSolution4.ReloadProject(ref projectGUID); } }
private void addIceBuilder_BeforeQueryStatus(object sender, EventArgs e) { try { OleMenuCommand command = sender as OleMenuCommand; if (command != null) { IVsProject p = DTEUtil.GetSelectedProject(); if (p != null) { if (DTEUtil.IsCppProject(p) || DTEUtil.IsCSharpProject(p)) { command.Enabled = !MSBuildUtils.IsIceBuilderEnabled(MSBuildUtils.LoadedProject( ProjectUtil.GetProjectFullPath(p), DTEUtil.IsCppProject(p), true)); } else { command.Enabled = false; } } } } catch (Exception ex) { Package.UnexpectedExceptionWarning(ex); throw; } }
public static IceBuilderProjectType IsIceBuilderEnabled(IVsProject project) { if (project != null) { IceBuilderProjectType type = IsCppProject(project) ? IceBuilderProjectType.CppProjectType : IsCSharpProject(project) ? IceBuilderProjectType.CsharpProjectType : IceBuilderProjectType.None; if (type != IceBuilderProjectType.None) { if (MSBuildUtils.IsIceBuilderEnabled(MSBuildUtils.LoadedProject(ProjectUtil.GetProjectFullPath(project), DTEUtil.IsCppProject(project), true))) { return(type); } } } return(IceBuilderProjectType.None); }
public static bool Upgrade(IVsProject project) { OldConfiguration oldConfiguration = new OldConfiguration(); Microsoft.Build.Evaluation.Project msbuildProject = MSBuildUtils.LoadedProject(ProjectUtil.GetProjectFullPath(project), DTEUtil.IsCppProject(project), true); if (oldConfiguration.Load(msbuildProject, true)) { if (DTEUtil.IsCppProject(project)) { return(UpgadeCppConfiguration(msbuildProject, oldConfiguration)); } else if (DTEUtil.IsCSharpProject(project)) { return(UpgradeCSharpConfiguration(DTEUtil.GetProject(project as IVsHierarchy), msbuildProject, oldConfiguration)); } } return(false); }
public static bool Upgrade(EnvDTE.Project project) { OldConfiguration oldConfiguration = new OldConfiguration(); Microsoft.Build.Evaluation.Project msbuildProject = MSBuildUtils.LoadedProject(project.FullName); if (oldConfiguration.Load(msbuildProject, true)) { if (DTEUtil.IsCppProject(project)) { return(UpgadeCppConfiguration(msbuildProject, oldConfiguration)); } else if (DTEUtil.IsCSharpProject(project)) { return(UpgradeCSharpConfiguration(project, msbuildProject, oldConfiguration)); } } return(false); }
public void InitializeProjects(List <EnvDTE.Project> projects) { ProjectConverter.TryUpgrade(projects); projects = DTEUtil.GetProjects(DTE.Solution); foreach (EnvDTE.Project project in projects) { List <EnvDTE.Project> build = new List <EnvDTE.Project>(); if (DTEUtil.IsIceBuilderEnabled(project)) { if (DTEUtil.IsCppProject(project)) { VCUtil.SetupSliceFilter(project); } FileTracker.Add(project); build.Add(project); } QueueProjectsForBuilding(build); } }
public void AddIceBuilderToProject(IVsProject p) { Microsoft.Build.Evaluation.Project project = MSBuildUtils.LoadedProject(ProjectUtil.GetProjectFullPath(p), DTEUtil.IsCppProject(p), true); if (MSBuildUtils.AddIceBuilderToProject(project)) { if (DTEUtil.IsCppProject(p)) { VCUtil.SetupSliceFilter(DTEUtil.GetProject(p as IVsHierarchy)); } else { String includeDirectories = ProjectUtil.GetProperty(p, PropertyNames.IncludeDirectories); if (String.IsNullOrEmpty(includeDirectories)) { ProjectUtil.SetProperty(p, PropertyNames.IncludeDirectories, @"$(IceHome)\slice"); } else if (includeDirectories.IndexOf(@"$(IceHome)\slice") == -1) { ProjectUtil.SetProperty(p, PropertyNames.IncludeDirectories, String.Format(@"$(IceHome)\slice;{0}", includeDirectories)); } ProjectUtil.AddAssemblyReference(DTEUtil.GetProject(p as IVsHierarchy), "Ice"); } ProjectUtil.SaveProject(p); IVsHierarchy hier = p as IVsHierarchy; Guid projectGUID = Guid.Empty; IVsSolution.GetGuidOfProject(hier, out projectGUID); IVsSolution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, hier, 0); project.Save(); try { ProjectCollection.GlobalProjectCollection.UnloadProject(project); } catch (System.Exception) { //expected if the project is not in the global project collection } IVsSolution4.ReloadProject(ref projectGUID); } }
public static string GetEvaluatedProperty(IVsProject project, string name, string defaultValue) { string value = MSBuildUtils.GetEvaluatedProperty(MSBuildUtils.LoadedProject(GetProjectFullPath(project), DTEUtil.IsCppProject(project), true), name); return(string.IsNullOrEmpty(value) ? defaultValue : value); }
public static void SetProperty(IVsProject project, string name, string value) { MSBuildUtils.SetProperty(MSBuildUtils.LoadedProject(GetProjectFullPath(project), DTEUtil.IsCppProject(project), true), "IceBuilder", name, value); }
public bool Build(IVsProject p, BuildCallback buildCallback, BuildLogger buildLogger) { MSBuildProject project = MSBuildUtils.LoadedProject(ProjectUtil.GetProjectFullPath(p), DTEUtil.IsCppProject(p), false); // // We need to set this before we acquire the build resources otherwise Msbuild // will not see the changes. // bool onlyLogCriticalEvents = project.ProjectCollection.OnlyLogCriticalEvents; project.ProjectCollection.Loggers.Add(buildLogger); project.ProjectCollection.OnlyLogCriticalEvents = false; uint cookie; int err = BuildManagerAccessor.AcquireBuildResources(VSBUILDMANAGERRESOURCE.VSBUILDMANAGERRESOURCE_DESIGNTIME | VSBUILDMANAGERRESOURCE.VSBUILDMANAGERRESOURCE_UITHREAD, out cookie); if (err != VSConstants.E_PENDING && err != VSConstants.S_OK) { ErrorHandler.ThrowOnFailure(err); } if (err == VSConstants.E_PENDING) { project.ProjectCollection.Loggers.Remove(buildLogger); project.ProjectCollection.OnlyLogCriticalEvents = onlyLogCriticalEvents; Dispatcher = Dispatcher.CurrentDispatcher; BuildAvailableEvent = new System.Threading.ManualResetEvent(false); BuildAvailableEvent.SafeWaitHandle = new SafeWaitHandle(BuildManagerAccessor.DesignTimeBuildAvailable, false); Thread t = new Thread(() => { BuildAvailableEvent.WaitOne(); Dispatcher.BeginInvoke(new Action(() => { Package.Instance.BuildNextProject(); })); }); t.Start(); return(false); } else { try { Dictionary <string, string> properties = new Dictionary <string, string>(); String platform = buildCallback.ProjectConfiguration.PlatformName; properties["Platform"] = platform.Equals("Any CPU") ? "AnyCPU" : platform; properties["Configuration"] = buildCallback.ProjectConfiguration.ConfigurationName; BuildRequestData buildRequest = new BuildRequestData( ProjectUtil.GetProjectFullPath(p), properties, null, new String[] { "IceBuilder_Compile" }, project.ProjectCollection.HostServices, BuildRequestDataFlags.IgnoreExistingProjectState | BuildRequestDataFlags.ReplaceExistingProjectInstance); BuildSubmission submission = BuildManager.DefaultBuildManager.PendBuildRequest(buildRequest); ErrorHandler.ThrowOnFailure(BuildManagerAccessor.RegisterLogger(submission.SubmissionId, buildLogger)); buildCallback.BeginBuild(); submission.ExecuteAsync((s) => { Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() => { project.ProjectCollection.Loggers.Remove(buildLogger); project.ProjectCollection.OnlyLogCriticalEvents = onlyLogCriticalEvents; BuildManagerAccessor.ReleaseBuildResources(cookie); BuildManagerAccessor.UnregisterLoggers(submission.SubmissionId); buildCallback.EndBuild(submission.BuildResult.OverallResult == BuildResultCode.Success); })); }, null); return(true); } catch (Exception) { project.ProjectCollection.Loggers.Remove(buildLogger); project.ProjectCollection.OnlyLogCriticalEvents = onlyLogCriticalEvents; BuildManagerAccessor.ReleaseBuildResources(cookie); throw; } } }
private void RemoveIceBuilderFromProject(IVsProject p) { String path = ProjectUtil.GetProjectFullPath(p); foreach (IVsProject p1 in _buildProjects) { if (path.Equals(ProjectUtil.GetProjectFullPath(p1))) { _buildProjects.Remove(p1); break; } } ProjectUtil.DeleteItems( ProjectUtil.GetGeneratedFiles(p).Aggregate( new List <String>(), (items, kv) => { items.AddRange(kv.Value); return(items); })); if (DTEUtil.IsCSharpProject(p)) { Directory.GetFiles(GetAssembliesDir(GetIceHome()), "*.dll") .ToList() .ForEach(item => { String name = Path.GetFileNameWithoutExtension(item); if (ProjectUtil.HasAssemblyReference(DTEUtil.GetProject(p as IVsHierarchy), name)) { ProjectUtil.RemoveAssemblyReference(DTEUtil.GetProject(p as IVsHierarchy), name); } }); } Microsoft.Build.Evaluation.Project project = MSBuildUtils.LoadedProject(path, DTEUtil.IsCppProject(p), true); MSBuildUtils.RemoveIceBuilderFromProject(project); ProjectUtil.SaveProject(p); Guid projectGUID = Guid.Empty; IVsHierarchy hier = p as IVsHierarchy; IVsSolution.GetGuidOfProject(hier, out projectGUID); IVsSolution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, hier, 0); project.Save(); try { ProjectCollection.GlobalProjectCollection.UnloadProject(project); } catch (System.Exception) { //expected if the project is not in the global project collection } IVsSolution4.ReloadProject(ref projectGUID); }
// // Set Ice Home and force projects to re evaluate changes in the imported project // public static void SetIceHome(List <IVsProject> projects, String iceHome, String iceVersion, String iceIntVersion, String iceVersionMM) { foreach (IVsProject p in projects) { if (DTEUtil.IsIceBuilderEnabled(p) != IceBuilderProjectType.None) { Microsoft.Build.Evaluation.Project project = MSBuildUtils.LoadedProject(ProjectUtil.GetProjectFullPath(p), DTEUtil.IsCppProject(p), true); ResolvedImport import = project.Imports.FirstOrDefault(i => i.ImportedProject.FullPath.EndsWith("IceBuilder.Common.props")); if (import.ImportedProject != null) { ProjectPropertyGroupElement group = import.ImportedProject.PropertyGroups.FirstOrDefault(g => g.Label.Equals("IceHome")); if (group != null) { group.SetProperty(Package.IceHomeValue, iceHome); group.SetProperty(Package.IceVersionValue, iceVersion); group.SetProperty(Package.IceIntVersionValue, iceIntVersion); group.SetProperty(Package.IceVersionMMValue, iceVersionMM); project.ReevaluateIfNecessary(); } } } } }