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 static void TrySetHintPath(VSLangProj80.Reference3 reference) { try { Microsoft.Build.Evaluation.Project project = MSBuildUtils.LoadedProject(reference.ContainingProject.FullName, false, false); Microsoft.Build.Evaluation.ProjectItem item = project.AllEvaluatedItems.FirstOrDefault(i => i.ItemType.Equals("Reference") && i.EvaluatedInclude.Split(",".ToCharArray()).ElementAt(0).Equals(reference.Name) ); if (item != null) { item.SetMetadataValue("HintPath", Path.Combine("$(IceAssembliesDir)", string.Format("{0}.dll", reference.Name))); } } catch (NotSupportedException) { } catch (NotImplementedException) { } catch (COMException) { } }
public static void TryUpgrade(List <EnvDTE.Project> projects) { String baseDir = String.Empty; if (!String.IsNullOrEmpty(Package.Instance.DTE2.Solution.FullName)) { baseDir = Path.GetDirectoryName(Package.Instance.DTE2.Solution.FullName); } Dictionary <String, EnvDTE.Project> upgradeProjects = new Dictionary <String, EnvDTE.Project>(); foreach (EnvDTE.Project project in projects) { if (new OldConfiguration().Load(MSBuildUtils.LoadedProject(project.FullName), false)) { upgradeProjects.Add( FileUtil.RelativePath(baseDir, project.FullName), project); } } if (upgradeProjects.Count > 0) { UpgradeDialog dialog = new UpgradeDialog(); dialog.StartPosition = FormStartPosition.CenterParent; dialog.Projects = upgradeProjects; dialog.ShowDialog(); } }
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; } }
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; } }
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); }
public static void SetupGenerated(IVsProject project, IceBuilderProjectType type) { if (type == IceBuilderProjectType.CppProjectType) { // // This will ensure that property reads don't use a cached project. // MSBuildUtils.LoadedProject(ProjectUtil.GetProjectFullPath(project), true, false); List <CppGeneratedFileSet> generated = GetCppGeneratedFiles(project); foreach (CppGeneratedFileSet fileset in generated) { SetupGenerated(project, fileset.configuration, "Source Files", fileset.sources, generated.Count > 1); SetupGenerated(project, fileset.configuration, "Header Files", fileset.headers, generated.Count > 1); } Package.Instance.FileTracker.Reap(GetProjectFullPath(project), GetCppGeneratedFiles(generated)); } else // C# project { EnvDTE.Project p = DTEUtil.GetProject(project as IVsHierarchy); Dictionary <String, List <String> > generated = GetCSharpGeneratedFiles(project); foreach (KeyValuePair <String, List <String> > i in generated) { foreach (String file in i.Value) { if (!Directory.Exists(Path.GetDirectoryName(file))) { Directory.CreateDirectory(Path.GetDirectoryName(file)); } if (!File.Exists(file)) { File.Create(file).Dispose(); } EnvDTE.ProjectItem item = FindProjectItem(file); if (item == null) { p.ProjectItems.AddFromFile(file); try { // // Remove the file otherwise it will be considered up to date. // File.Delete(file); } catch (Exception) { } } } } Package.Instance.FileTracker.Reap(GetProjectFullPath(project), generated); } }
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); }
private void RemoveIceBuilderFromProject(EnvDTE.Project p) { Microsoft.Build.Evaluation.Project project = MSBuildUtils.LoadedProject(p.FullName); MSBuildUtils.RemoveIceBuilderFromProject(project); foreach (EnvDTE.Project p1 in _buildProjects) { if (p.FullName.Equals(p.FullName)) { _buildProjects.Remove(p1); break; } } ProjectUtil.DeleteItems(p, ProjectUtil.GetGeneratedFiles(p).Aggregate( new List <String>(), (items, kv) => { items.AddRange(kv.Value); return(items); })); Directory.GetFiles(GetAssembliesDir(GetIceHome()), "*.dll") .ToList() .ForEach(item => { String name = Path.GetFileNameWithoutExtension(item); if (ProjectUtil.HasAssemblyReference(p, name)) { ProjectUtil.RemoveAssemblyReference(p, name); } }); p.Save(); Guid projectGUID = Guid.Empty; IVsHierarchy hier = DTEUtil.GetIVsHierarchy(p); IVsSolution.GetGuidOfProject(hier, out projectGUID); IVsSolution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, hier, 0); project.Save(); IVsSolution4.ReloadProject(ref projectGUID); }
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); }
// // Set Ice Home and force projects to re evaluate changes in the imported project // public static void SetIceHome(List <EnvDTE.Project> projects, String iceHome, String iceVersion, String iceIntVersion, String iceVersionMM) { foreach (EnvDTE.Project p in projects) { Microsoft.Build.Evaluation.Project project = MSBuildUtils.LoadedProject(p.FullName); 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(); } } } }
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 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; } } }
public static void SetProperty(EnvDTE.Project project, String name, String value) { MSBuildUtils.SetProperty(MSBuildUtils.LoadedProject(project.FullName), "IceBuilder", name, value); }
public static String GetProperty(EnvDTE.Project project, String name, String defaultValue) { String value = MSBuildUtils.GetProperty(MSBuildUtils.LoadedProject(project.FullName), name); return(String.IsNullOrEmpty(value) ? defaultValue : value); }
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 static bool IsIceBuilderEnabled(EnvDTE.Project project) { return(project != null && !String.IsNullOrEmpty(project.FullName) && (IsCppProject(project) || IsCSharpProject(project)) && MSBuildUtils.IsIceBuilderEnabeld(MSBuildUtils.LoadedProject(project.FullName))); }