//
        // 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 = 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", StringComparison.CurrentCultureIgnoreCase));
                        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();
                        }
                    }
                }
            }
        }
Exemple #2
0
 public int OnAfterSave(uint docCookie)
 {
     ThreadHelper.JoinableTaskFactory.Run(async() =>
     {
         await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
         try
         {
             if (Package.Instance.AutoBuilding)
             {
                 IVsProject project = null;
                 uint item          = 0;
                 string path        = null;
                 GetDocumentInfo(docCookie, ref project, ref item, ref path);
                 if (ProjectUtil.IsSliceFileName(path) && project.IsMSBuildIceBuilderInstalled())
                 {
                     Package.Instance.QueueProjectsForBuilding(new List <IVsProject>(new IVsProject[] { project }));
                 }
             }
         }
         catch (Exception ex)
         {
             Package.UnexpectedExceptionWarning(ex);
         }
     });
     return(0);
 }
 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;
     }
 }
Exemple #4
0
 public int OnQueryRenameFiles(IVsProject project, int filesLength, string[] oldNames, string[] newNames,
                               VSQUERYRENAMEFILEFLAGS[] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult,
                               VSQUERYRENAMEFILERESULTS[] rgResults)
 {
     ThreadHelper.JoinableTaskFactory.Run(async() =>
     {
         await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
         try
         {
             if (project.IsMSBuildIceBuilderInstalled())
             {
                 for (int i = 0; i < filesLength; ++i)
                 {
                     if (ProjectUtil.IsSliceFileName(newNames[i]))
                     {
                         if (!ProjectUtil.CheckGenerateFileIsValid(project, newNames[i]))
                         {
                             rgResults[i]      = VSQUERYRENAMEFILERESULTS.VSQUERYRENAMEFILERESULTS_RenameNotOK;
                             pSummaryResult[i] = VSQUERYRENAMEFILERESULTS.VSQUERYRENAMEFILERESULTS_RenameNotOK;
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             Package.UnexpectedExceptionWarning(ex);
         }
     });
     return(0);
 }
Exemple #5
0
        public string GetAssembliesDir(IVsProject project = null)
        {
            if (project != null)
            {
                string assembliesDir = ProjectUtil.GetEvaluatedProperty(project, IceAssembliesDir);
                if (Directory.Exists(assembliesDir))
                {
                    return(assembliesDir);
                }
            }
            string iceHome = GetIceHome(project);

            if (Directory.Exists(Path.Combine(iceHome, "Assemblies")))
            {
                return(Path.Combine(iceHome, "Assemblies"));
            }
            else if (Directory.Exists(Path.Combine(iceHome, "csharp", "Assemblies")))
            {
                return(Path.Combine(iceHome, "csharp", "Assemblies"));
            }
            else if (Directory.Exists(Path.Combine(iceHome, "lib")))
            {
                return(Path.Combine(iceHome, "lib"));
            }

            return(string.Empty);
        }
Exemple #6
0
 public int OnQueryRenameFiles(IVsProject project, int filesLength, string[] oldNames, string[] newNames,
                               VSQUERYRENAMEFILEFLAGS[] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult,
                               VSQUERYRENAMEFILERESULTS[] rgResults)
 {
     try
     {
         if (project.IsMSBuildIceBuilderInstalled())
         {
             for (int i = 0; i < filesLength; ++i)
             {
                 if (ProjectUtil.IsSliceFileName(newNames[i]))
                 {
                     if (!ProjectUtil.CheckGenerateFileIsValid(project, newNames[i]))
                     {
                         rgResults[i]      = VSQUERYRENAMEFILERESULTS.VSQUERYRENAMEFILERESULTS_RenameNotOK;
                         pSummaryResult[i] = VSQUERYRENAMEFILERESULTS.VSQUERYRENAMEFILERESULTS_RenameNotOK;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Package.UnexpectedExceptionWarning(ex);
     }
     return(0);
 }
Exemple #7
0
 public int OnAfterRemoveFiles(int projectsLength, int filesLength, IVsProject[] projects, int[] indices,
                               string[] names, VSREMOVEFILEFLAGS[] rgFlags)
 {
     ThreadHelper.JoinableTaskFactory.Run(async() =>
     {
         await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
         try
         {
             for (int i = 0; i < projectsLength; ++i)
             {
                 IVsProject project = projects[i];
                 if (project.IsMSBuildIceBuilderInstalled())
                 {
                     int j = indices[i];
                     int k = i < (projectsLength - 1) ? indices[i + 1] : filesLength;
                     for (; j < k; ++j)
                     {
                         string path = names[i];
                         if (ProjectUtil.IsSliceFileName(path))
                         {
                             ProjectUtil.SetupGenerated(project);
                             break;
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             Package.UnexpectedExceptionWarning(ex);
         }
     });
     return(0);
 }
 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);
 }
Exemple #9
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)
         {
             IVsProject project = projects[i];
             if (project.IsMSBuildIceBuilderInstalled())
             {
                 int j = indices[i];
                 int k = i < (projectsLength - 1) ? indices[i + 1] : filesLength;
                 for (; j < k; ++j)
                 {
                     string oldPath = oldNames[i];
                     string newPath = newNames[j];
                     if (ProjectUtil.IsSliceFileName(oldPath) || ProjectUtil.IsSliceFileName(newPath))
                     {
                         ProjectUtil.SetupGenerated(project);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Package.UnexpectedExceptionWarning(ex);
     }
     return(0);
 }
Exemple #10
0
 public int OnQueryAddFiles(IVsProject project, int length, string[] files,
                            VSQUERYADDFILEFLAGS[] rgFlags, VSQUERYADDFILERESULTS[] pSummaryResult,
                            VSQUERYADDFILERESULTS[] rgResults)
 {
     try
     {
         if (files.Any(f => ProjectUtil.IsSliceFileName(f)))
         {
             if (project.IsMSBuildIceBuilderInstalled())
             {
                 for (int i = 0; i < length; ++i)
                 {
                     if (ProjectUtil.IsSliceFileName(files[i]))
                     {
                         if (!ProjectUtil.CheckGenerateFileIsValid(project, files[i]))
                         {
                             rgResults[i]      = VSQUERYADDFILERESULTS.VSQUERYADDFILERESULTS_AddNotOK;
                             pSummaryResult[i] = VSQUERYADDFILERESULTS.VSQUERYADDFILERESULTS_AddNotOK;
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Package.UnexpectedExceptionWarning(ex);
     }
     return(0);
 }
Exemple #11
0
        private void includeList_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (!_editing)
            {
                string path = includeList.Items[e.Index].ToString();
                if (!string.IsNullOrEmpty(path) && path.IndexOf('$') == -1)
                {
                    string projectDir = Path.GetFullPath(Path.GetDirectoryName(ProjectUtil.GetProjectFullPath(PropertyPage.Project)));
                    bool   absolute   = Path.IsPathRooted(path);

                    if (e.NewValue == CheckState.Unchecked)
                    {
                        if (absolute)
                        {
                            includeList.Items[e.Index]           = FileUtil.RelativePath(projectDir, path);
                            PropertyPage.ConfigurationView.Dirty = true;
                        }
                    }
                    else if (e.NewValue == CheckState.Checked)
                    {
                        if (!absolute)
                        {
                            includeList.Items[e.Index]           = Path.GetFullPath(Path.Combine(projectDir, path));
                            PropertyPage.ConfigurationView.Dirty = true;
                        }
                    }
                }
            }
        }
        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();
            }
        }
 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);
     }
 }
 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 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 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);
 }
Exemple #17
0
 public void BeginBuild(string platform, string configuration)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     _outputPane.OutputString(
         string.Format("------ Ice Builder Build started: Project: {0}, Configuration: {1} {2} ------\n",
                       ProjectUtil.GetProjectName(_project), configuration, platform));
 }
 public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame)
 {
     try
     {
         if (fFirstShow != 0)
         {
             IVsProject project = null;
             uint       item    = 0;
             string     path    = null;
             GetDocumentInfo(docCookie, ref project, ref item, ref path);
             if (project != null && !string.IsNullOrEmpty(path))
             {
                 if (Package.Instance.FileTracker.Contains(ProjectUtil.GetProjectFullPath(project), path))
                 {
                     ProjectItem i = ProjectUtil.GetProjectItem(project, item);
                     if (i != null)
                     {
                         i.Document.ReadOnly = true;
                     }
                 }
             }
         }
     }
     catch (Exception)
     {
         // Could happend with some document types
     }
     return(0);
 }
 public int OnAfterRemoveFiles(int projectsLength, int filesLength, IVsProject[] projects, int[] indices,
                               string[] names, VSREMOVEFILEFLAGS[] rgFlags)
 {
     try
     {
         for (int i = 0; i < projectsLength; ++i)
         {
             IVsProject            project     = projects[i];
             IceBuilderProjectType projectType = DTEUtil.IsIceBuilderNuGetInstalled(project);
             if (projectType != IceBuilderProjectType.None)
             {
                 int j = indices[i];
                 int k = i < (projectsLength - 1) ? indices[i + 1] : filesLength;
                 for (; j < k; ++j)
                 {
                     string path = names[i];
                     if (ProjectUtil.IsSliceFileName(path))
                     {
                         ProjectUtil.SetupGenerated(project, projectType);
                         break;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Package.UnexpectedExceptionWarning(ex);
     }
     return(0);
 }
 public void BeginBuild()
 {
     OutputPane.OutputString(
         string.Format("------ Ice Builder Build started: Project: {0}, Configuration: {1} {2} ------\n",
                       ProjectUtil.GetProjectName(Project),
                       ProjectConfiguration.ConfigurationName,
                       ProjectConfiguration.PlatformName));
 }
        CheckGenerateFileIsValid(IVsProject project, IceBuilderProjectType projectType, String path)
        {
            if (projectType == IceBuilderProjectType.CsharpProjectType)
            {
                String outputDir       = ProjectUtil.GetOutputDir(project, false, true);
                String generatedSource = ProjectUtil.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,
                                                         ProjectUtil.GetPathRelativeToProject(project, generatedSource),
                                                         ProjectUtil.GetPathRelativeToProject(project, path)));
                    return(false);
                }
            }
            else if (projectType == IceBuilderProjectType.CppProjectType)
            {
                String source = ProjectUtil.GetCppGeneratedSourceItemPath(project, path);
                String header = ProjectUtil.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,
                                                             ProjectUtil.GetPathRelativeToProject(project, generatedSource),
                                                             ProjectUtil.GetPathRelativeToProject(project, generatedHeader),
                                                             ProjectUtil.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 void Add(IVsProject project, IceBuilderProjectType type)
        {
            String projectFullPath = ProjectUtil.GetProjectFullPath(project);

            Remove(projectFullPath);
            _generated.Add(projectFullPath,
                           type == IceBuilderProjectType.CsharpProjectType ?
                           ProjectUtil.GetCSharpGeneratedFiles(project) :
                           ProjectUtil.GetCppGeneratedFiles(ProjectUtil.GetCppGeneratedFiles(project)));
        }
        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);
            }
        }
Exemple #25
0
 public int OnAfterAddFilesEx(int projectsLength, int filesLength, IVsProject[] projects, int[] indices,
                              string[] names, VSADDFILEFLAGS[] rgFlags)
 {
     ThreadHelper.JoinableTaskFactory.Run(async() =>
     {
         await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
         try
         {
             for (int i = 0; i < projectsLength; ++i)
             {
                 IVsProject project = projects[i];
                 if (project.IsMSBuildIceBuilderInstalled())
                 {
                     int j = indices[i];
                     int k = i < (projectsLength - 1) ? indices[i + 1] : filesLength;
                     for (; j < k; ++j)
                     {
                         string path = names[i];
                         if (ProjectUtil.IsSliceFileName(path))
                         {
                             //
                             // Ensure the .ice file item has SliceCompile ItemType
                             //
                             var projectItem = project.GetProjectItem(path);
                             if (projectItem != null)
                             {
                                 project.EnsureIsCheckout();
                                 var property = projectItem.Properties.Item("ItemType");
                                 if (property != null && !property.Value.Equals("SliceCompile"))
                                 {
                                     property.Value = "SliceCompile";
                                 }
                             }
                             ProjectUtil.AddGeneratedFiles(project, path);
                             break;
                         }
                     }
                 }
             }
         }
         catch (OperationCanceledException)
         {
             // Ignore, this could happen if the project is reloaded
         }
         catch (Exception ex)
         {
             Package.UnexpectedExceptionWarning(ex);
         }
     });
     return(0);
 }
        public static void GetIceBuilderItems(IVsHierarchy h, uint itemId, ref List <String> items)
        {
            IntPtr nestedValue = IntPtr.Zero;
            uint   nestedId    = 0;
            Guid   nestedGuid  = typeof(IVsHierarchy).GUID;
            int    result      = h.GetNestedHierarchy(itemId, ref nestedGuid, out nestedValue, out nestedId);

            if (ErrorHandler.Succeeded(result) && nestedValue != IntPtr.Zero && nestedId == VSConstants.VSITEMID_ROOT)
            {
                // Get the nested hierachy
                IVsProject project = System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(nestedValue) as IVsProject;
                System.Runtime.InteropServices.Marshal.Release(nestedValue);
                if (project != null)
                {
                    GetIceBuilderItems(project as IVsHierarchy, VSConstants.VSITEMID_ROOT, ref items);
                }
            }
            else
            {
                // Get the first visible child node
                object value;
                result = h.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_FirstVisibleChild, out value);
                while (result == VSConstants.S_OK && value != null)
                {
                    if (value is int && (uint)(int)value == VSConstants.VSITEMID_NIL)
                    {
                        // No more nodes
                        break;
                    }
                    else
                    {
                        uint child = Convert.ToUInt32(value);

                        value  = null;
                        result = h.GetProperty(child, (int)__VSHPROPID.VSHPROPID_Name, out value);
                        String path = value as String;
                        if (ProjectUtil.IsSliceFileName(path))
                        {
                            items.Add(path);
                        }

                        GetIceBuilderItems(h, child, ref items);

                        // Get the next visible sibling node
                        value  = null;
                        result = h.GetProperty(child, (int)__VSHPROPID.VSHPROPID_NextVisibleSibling, out value);
                    }
                }
            }
        }
Exemple #27
0
        private void PackageInstalled()
        {
            var projects = DTEUtil.GetProjects();

            foreach (IVsProject project in projects)
            {
                // Projects that are not being track has not been previous initialized
                // initialize will do nothing in zeroc.icebuilder.msbuild package is
                // not installed
                if (!FileTracker.Contains(ProjectUtil.GetProjectFullPath(project)))
                {
                    InitializeProject(project);
                }
            }
        }
Exemple #28
0
        private void btnOutputDirectoryBrowse_Click(object sender, EventArgs e)
        {
            string projectDir   = Path.GetFullPath(Path.GetDirectoryName(ProjectUtil.GetProjectFullPath(Page.Project)));
            string selectedPath = UIUtil.BrowserFolderDialog(Handle, "Output Directory", projectDir);

            if (!string.IsNullOrEmpty(selectedPath))
            {
                selectedPath = FileUtil.RelativePath(projectDir, selectedPath);
                OutputDir    = string.IsNullOrEmpty(selectedPath) ? "." : selectedPath;
                if (!txtOutputDir.Text.Equals(Page.Settings.OutputDir))
                {
                    Dirty = isDirty();
                }
            }
        }
        public static List <String> GetGeneratedFiles(EnvDTE.Project project, String sliceFile)
        {
            List <String> generated = new List <String>();

            if (DTEUtil.IsCSharpProject(project))
            {
                generated.Add(ProjectUtil.GetCSharpGeneratedItemFullPath(project, sliceFile));
            }
            else
            {
                generated.Add(ProjectUtil.GetCppGeneratedSourceItemFullPath(project, sliceFile));
                generated.Add(ProjectUtil.GetCppGeneratedHeaderItemFullPath(project, sliceFile));
            }
            return(generated);
        }
Exemple #30
0
        private void btnSelectInclude_Clicked(object sender, EventArgs e)
        {
            string projectDir   = Path.GetFullPath(Path.GetDirectoryName(ProjectUtil.GetProjectFullPath(PropertyPage.Project)));
            string selectedPath = UIUtil.BrowserFolderDialog(Handle, "Slice Include Directory",
                                                             string.IsNullOrEmpty(_editingIncludeDir) ? projectDir : _editingIncludeDir);

            if (string.IsNullOrEmpty(selectedPath) && !string.IsNullOrEmpty(_editingIncludeDir))
            {
                _txtInclude.Text = _editingIncludeDir;
            }
            else
            {
                _txtInclude.Text = FileUtil.RelativePath(projectDir, selectedPath);
            }
            EndEditing(true);
        }