public int OnQueryAddFiles(IVsProject p, int length, string[] files, VSQUERYADDFILEFLAGS[] rgFlags, VSQUERYADDFILERESULTS[] pSummaryResult, VSQUERYADDFILERESULTS[] rgResults) { try { EnvDTE.Project project = DTEUtil.GetProject(p as IVsHierarchy); if (DTEUtil.IsIceBuilderEnabled(project)) { for (int i = 0; i < length; ++i) { String path = files[i]; if (Path.GetExtension(path).Equals(".ice")) { if (!ProjectUtil.CheckGenerateFileIsValid(project, path)) { pSummaryResult[i] = VSQUERYADDFILERESULTS.VSQUERYADDFILERESULTS_AddNotOK; } } } } } catch (Exception ex) { Package.UnexpectedExceptionWarning(ex); throw; } return(0); }
public void InitializeProjects(List <IVsProject> upgradeProjects) { ProjectConverter.TryUpgrade(upgradeProjects); List <IVsProject> projects = DTEUtil.GetProjects(); List <IVsProject> sliceProjects = new List <IVsProject>(); foreach (IVsProject project in projects) { IceBuilderProjectType projectType = DTEUtil.IsIceBuilderEnabled(project); if (projectType != IceBuilderProjectType.None) { if (projectType == IceBuilderProjectType.CppProjectType) { VCUtil.SetupSliceFilter(DTEUtil.GetProject(project as IVsHierarchy)); } if (AutoBuilding) { sliceProjects.Add(project); } else { FileTracker.Add(project, projectType); } } } if (AutoBuilding) { QueueProjectsForBuilding(sliceProjects); } }
public int OnAfterAddFilesEx(int projectsLength, int filesLength, IVsProject[] projects, int[] indices, string[] paths, VSADDFILEFLAGS[] rgFlags) { try { for (int i = 0; i < projectsLength; ++i) { EnvDTE.Project project = DTEUtil.GetProject(projects[i] as IVsHierarchy); if (DTEUtil.IsIceBuilderEnabled(project)) { int j = indices[i]; int k = i < (projectsLength - 1) ? indices[i + 1] : filesLength; for (; j < k; ++j) { if (ProjectUtil.IsSliceFileName(paths[j])) { ProjectUtil.SetupGenerated(project, paths[j]); } } } } } catch (Exception ex) { Package.UnexpectedExceptionWarning(ex); throw; } return(0); }
public int OnQueryRenameFiles(IVsProject ivsProject, int filesLength, string[] oldNames, string[] newNames, VSQUERYRENAMEFILEFLAGS[] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult, VSQUERYRENAMEFILERESULTS[] rgResults) { try { EnvDTE.Project project = DTEUtil.GetProject(ivsProject as IVsHierarchy); if (DTEUtil.IsIceBuilderEnabled(project)) { for (int i = 0; i < filesLength; ++i) { if (Path.GetExtension(oldNames[i]).Equals(".ice") && Path.GetExtension(newNames[i]).Equals(".ice")) { if (!ProjectUtil.CheckGenerateFileIsValid(project, newNames[i])) { rgResults[i] = VSQUERYRENAMEFILERESULTS.VSQUERYRENAMEFILERESULTS_RenameNotOK; } } } } } catch (Exception ex) { Package.UnexpectedExceptionWarning(ex); throw; } return(0); }
public int OnAfterRenameFiles(int projectsLength, int filesLength, IVsProject[] projects, int[] indices, string[] oldNames, string[] newNames, VSRENAMEFILEFLAGS[] rgFlags) { try { for (int i = 0; i < projectsLength; ++i) { EnvDTE.Project project = DTEUtil.GetProject(projects[i] as IVsHierarchy); if (DTEUtil.IsIceBuilderEnabled(project)) { int j = indices[i]; int k = i < (projectsLength - 1) ? indices[i + 1] : filesLength; for (; j < k; ++j) { ProjectUtil.DeleteItems(project, ProjectUtil.GetGeneratedFiles(project, oldNames[j])); if (ProjectUtil.IsSliceFileName(newNames[j])) { ProjectUtil.SetupGenerated(project, newNames[j]); } } Package.Instance.FileTracker.Reap(project); } } } catch (Exception ex) { Package.UnexpectedExceptionWarning(ex); throw; } return(0); }
public static void SetupGenerated(IVsProject project, EnvDTE.Configuration configuration, String filter, List <string> files, bool generatedFilesPerConfiguration) { List <string> missing = new List <string>(); foreach (String file in files) { if (!Directory.Exists(Path.GetDirectoryName(file))) { Directory.CreateDirectory(Path.GetDirectoryName(file)); } if (!File.Exists(file)) { File.Create(file).Dispose(); } int found; uint id; VSDOCUMENTPRIORITY[] priority = new VSDOCUMENTPRIORITY[1]; project.IsDocumentInProject(file, out found, priority, out id); if (found == 0) { missing.Add(file); } } Package.Instance.VCUtil.AddGeneratedFiles(DTEUtil.GetProject(project as IVsHierarchy), configuration, filter, missing, generatedFilesPerConfiguration); }
CheckGenerateFileIsValid(IVsProject project, IceBuilderProjectType projectType, string path) { if (projectType == IceBuilderProjectType.CsharpProjectType) { string outputDir = GetOutputDir(project, false, true); string generatedSource = GetCSharpGeneratedItemPath(Path.GetFileName(path)); if (File.Exists(generatedSource)) { const string message = "A file named '{0}' already exists.\nIf you want to add '{1}' first remove '{0}'."; UIUtil.ShowErrorDialog("Ice Builder", string.Format(message, GetPathRelativeToProject(project, generatedSource), GetPathRelativeToProject(project, path))); return(false); } } else if (projectType == IceBuilderProjectType.CppProjectType) { string source = GetCppGeneratedSourceItemPath(project, path); string header = GetCppGeneratedHeaderItemPath(project, path); EnvDTE.Project p = DTEUtil.GetProject(project as IVsHierarchy); foreach (EnvDTE.Configuration config in p.ConfigurationManager) { string outputDir = Package.Instance.VCUtil.Evaluate(config, "$(IceBuilderOutputDir)"); outputDir = Path.GetFullPath(Path.Combine(GetProjectBaseDirectory(project), outputDir)); string headerOutputDir = Package.Instance.VCUtil.Evaluate(config, "$(IceBuilderHeaderOutputDir)"); if (string.IsNullOrEmpty(headerOutputDir)) { headerOutputDir = outputDir; } else { headerOutputDir = Path.GetFullPath(Path.Combine(GetProjectBaseDirectory(project), headerOutputDir)); } string generatedSource = Path.GetFullPath(Path.Combine(outputDir, source)); string generatedHeader = Path.GetFullPath(Path.Combine(headerOutputDir, header)); if (File.Exists(generatedSource) || File.Exists(generatedHeader)) { const string message = "A file named '{0}' or '{1}' already exists.\nIf you want to add '{2}' first remove '{0}' and '{1}'."; UIUtil.ShowErrorDialog("Ice Builder", string.Format(message, GetPathRelativeToProject(project, generatedSource), GetPathRelativeToProject(project, generatedHeader), GetPathRelativeToProject(project, path))); return(false); } } } return(true); }
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 int OnAfterLoadProject(IVsHierarchy hierarchyOld, IVsHierarchy hierarchyNew) { try { EnvDTE.Project project = DTEUtil.GetProject(hierarchyNew); if (project != null) { Package.Instance.InitializeProjects(new List <EnvDTE.Project>(new EnvDTE.Project[] { project })); } } catch (Exception ex) { Package.UnexpectedExceptionWarning(ex); throw; } return(0); }
public int OnBeforeUnloadProject(IVsHierarchy pRealHierarchy, IVsHierarchy pStubHierarchy) { try { EnvDTE.Project project = DTEUtil.GetProject(pRealHierarchy); if (project != null) { Package.Instance.FileTracker.Remove(project); } } catch (Exception ex) { Package.UnexpectedExceptionWarning(ex); throw; } return(0); }
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 void Upgrade(List <IVsProject> projects, UpgradeProgressCallback progressCallback) { string solutionDir = Path.GetDirectoryName(Package.Instance.DTE2.Solution.FullName); Dispatcher dispatcher = Dispatcher.CurrentDispatcher; Thread t = new Thread(() => { for (int i = 0; i < projects.Count; ++i) { if (progressCallback.Canceled) { break; } IVsProject project = projects[i]; string projectName = FileUtil.RelativePath(solutionDir, ProjectUtil.GetProjectFullPath(project)); if (Upgrade(project)) { EnvDTE.Project p = DTEUtil.GetProject(project as IVsHierarchy); if (p.Globals != null) { foreach (string name in OldPropertyNames) { if (p.Globals.get_VariableExists(name)) { p.Globals[name] = string.Empty; p.Globals.set_VariablePersists(name, false); } } } Package.Instance.AddIceBuilderToProject(project); } dispatcher.Invoke( new Action(() => { progressCallback.ReportProgress(projectName, i); })); } dispatcher.BeginInvoke(new Action(() => progressCallback.Finished())); }); t.Start(); }
public void Apply() { try { Settings.OutputDir = ConfigurationView.OutputDir; Settings.AllowIcePrefix = ConfigurationView.Ice == CheckState.Checked ? true : false; Settings.Checksum = ConfigurationView.Checksum == CheckState.Checked ? true : false; Settings.Stream = ConfigurationView.Streaming == CheckState.Checked ? true : false; Settings.Tie = ConfigurationView.Tie == CheckState.Checked ? true : false; Settings.Underscore = ConfigurationView.Underscores == CheckState.Checked ? true : false; Settings.IncludeDirectories = String.Join(";", ConfigurationView.IncludeDirectories.Values); Settings.AdditionalOptions = ConfigurationView.AdditionalOptions; List <String> referencedAssemblies = ConfigurationView.ReferencedAssemblies; String assembliesDir = ProjectUtil.GetEvaluatedProperty(Project, "IceAssembliesDir"); foreach (String assembly in ConfigurationView.Assemblies) { EnvDTE.Project p = DTEUtil.GetProject(Project as IVsHierarchy); if (ProjectUtil.HasAssemblyReference(p, assembly)) { if (!referencedAssemblies.Contains(assembly)) { ProjectUtil.RemoveAssemblyReference(p, assembly); } } else { if (referencedAssemblies.Contains(assembly)) { ProjectUtil.AddAssemblyReference(p, assembliesDir, assembly); } } } Settings.Save(); ConfigurationView.Dirty = false; } catch (Exception ex) { Package.UnexpectedExceptionWarning(ex); throw; } }
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 void LoadReferencedAssemblies() { if (!String.IsNullOrEmpty(AssembliesDir)) { try { String[] assemblies = Directory.GetFiles(AssembliesDir, "*.dll"); foreach (String assembly in assemblies) { String name = Path.GetFileNameWithoutExtension(assembly); referencedAssemblies.Items.Add(name); if (ProjectUtil.HasAssemblyReference(DTEUtil.GetProject(Page.Project as IVsHierarchy), name)) { referencedAssemblies.SetItemCheckState(referencedAssemblies.Items.Count - 1, CheckState.Checked); } } } catch (IOException) { } } }
public void SetObjects(uint cObjects, Object[] objects) { try { if (objects != null && cObjects > 0) { IVsBrowseObject browse = objects[0] as IVsBrowseObject; if (browse != null) { IVsHierarchy hier; uint id; browse.GetProjectItem(out hier, out id); Project = DTEUtil.GetProject(hier); if (Project != null) { Settings = new ProjectSettigns(Project); Settings.Load(); ConfigurationView.OutputDir = Settings.OutputDir; ConfigurationView.Ice = Settings.AllowIcePrefix ? CheckState.Checked : CheckState.Unchecked; ConfigurationView.Checksum = Settings.Checksum ? CheckState.Checked : CheckState.Unchecked; ConfigurationView.Streaming = Settings.Stream ? CheckState.Checked : CheckState.Unchecked; ConfigurationView.Tie = Settings.Tie ? CheckState.Checked : CheckState.Unchecked; ConfigurationView.Underscores = Settings.Underscore ? CheckState.Checked : CheckState.Unchecked; ConfigurationView.IncludeDirectories.Values = new List <String>( Settings.IncludeDirectories.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); ConfigurationView.AdditionalOptions = Settings.AdditionalOptions; ConfigurationView.LoadReferencedAssemblies(); ConfigurationView.Dirty = false; } } } } catch (Exception ex) { Package.UnexpectedExceptionWarning(ex); throw; } }
GetCppGeneratedFiles(IVsProject project) { List <string> outputDirectories = new List <string>(); List <string> headerOutputDirectories = new List <string>(); // // Check if the output directories expand to different values in each configuration, if that is the case we // add generated files per configuration, and use ExcludeFromBuild to disable the file in all the configurations // but the one matching the configuration expanded value of the properties. // // IVsBuildPropertyStorage propertyStorage = project as IVsBuildPropertyStorage; IVsCfg[] configurations = GetProjectConfigurations(project); foreach (IVsCfg config in configurations) { string value; string configName; config.get_DisplayName(out configName); propertyStorage.GetPropertyValue("IceBuilderOutputDir", configName, (uint)_PersistStorageType.PST_PROJECT_FILE, out value); if (!string.IsNullOrEmpty(value) && !outputDirectories.Contains(value)) { outputDirectories.Add(value); } propertyStorage.GetPropertyValue("IceBuilderHeaderOutputDir", configName, (uint)_PersistStorageType.PST_PROJECT_FILE, out value); if (!string.IsNullOrEmpty(value) && !outputDirectories.Contains(value)) { headerOutputDirectories.Add(value); } } bool generateFilesPerConfiguration = headerOutputDirectories.Count > 1 || outputDirectories.Count > 1; List <CppGeneratedFileSet> generated = new List <CppGeneratedFileSet>(); List <string> items = GetIceBuilderItems(project); if (items.Count > 0) { string projectDir = GetProjectBaseDirectory(project); string outputDir = GetOutputDir(project, false, false); string headerOutputDir = GetOutputDir(project, true, false); string sourceExt = GetEvaluatedProperty(project, PropertyNames.SourceExt, ".cpp"); string headerExt = GetEvaluatedProperty(project, PropertyNames.HeaderExt, ".h"); EnvDTE.Project p = DTEUtil.GetProject(project as IVsHierarchy); if (generateFilesPerConfiguration) { foreach (EnvDTE.Configuration configuration in p.ConfigurationManager) { string outputDirEvaluated = Path.Combine(projectDir, Package.Instance.VCUtil.Evaluate(configuration, outputDir)); string headerOutputDirEvaluated = Path.Combine(projectDir, Package.Instance.VCUtil.Evaluate(configuration, headerOutputDir)); CppGeneratedFileSet fileset = new CppGeneratedFileSet(); fileset.configuration = configuration; fileset.headers = new List <string>(); fileset.sources = new List <string>(); foreach (string item in items) { fileset.filename = item; fileset.sources.Add(Path.GetFullPath(Path.Combine(outputDirEvaluated, GetGeneratedItemPath(item, sourceExt)))); fileset.headers.Add(Path.GetFullPath(Path.Combine(headerOutputDirEvaluated, GetGeneratedItemPath(item, headerExt)))); } generated.Add(fileset); } } else { EnvDTE.Configuration configuration = p.ConfigurationManager.ActiveConfiguration; string outputDirEvaluated = Path.Combine(projectDir, Package.Instance.VCUtil.Evaluate(configuration, outputDir)); string headerOutputDirEvaluated = Path.Combine(projectDir, Package.Instance.VCUtil.Evaluate(configuration, headerOutputDir)); CppGeneratedFileSet fileset = new CppGeneratedFileSet(); fileset.configuration = configuration; fileset.headers = new List <string>(); fileset.sources = new List <string>(); foreach (string item in items) { fileset.filename = item; fileset.sources.Add(Path.GetFullPath(Path.Combine(outputDirEvaluated, GetGeneratedItemPath(item, sourceExt)))); fileset.headers.Add(Path.GetFullPath(Path.Combine(headerOutputDirEvaluated, GetGeneratedItemPath(item, headerExt)))); } generated.Add(fileset); } } return(generated); }