public static void AddCSharpGeneratedFiles(IVsProject project, string file)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var projectDir = project.GetProjectBaseDirectory();
            var dteproject = project.GetDTEProject();
            var fileset    = GetCsharpGeneratedFiles(project, dteproject, projectDir, file);

            //
            // First remove any generated items that are not in the
            // current generated items set for this Slice file
            //
            project.DeleteItems(project.WithProject((MSProject msproject) =>
            {
                return(msproject.AllEvaluatedItems.Where(
                           item =>
                {
                    if (item.ItemType.Equals("Compile") && item.HasMetadata("SliceCompileSource"))
                    {
                        if (item.GetMetadataValue("SliceCompileSource").Equals(fileset.filename))
                        {
                            return !fileset.sources.ContainsKey(Path.GetFullPath(Path.Combine(projectDir, item.EvaluatedInclude)));
                        }
                    }
                    return false;
                }).Select(item => Path.Combine(projectDir, item.EvaluatedInclude)).ToList());
            }));

            foreach (var entry in fileset.sources)
            {
                AddCSharpGeneratedItem(project, dteproject,
                                       projectDir,
                                       FileUtil.RelativePath(projectDir, fileset.filename),
                                       FileUtil.RelativePath(projectDir, entry.Key));
            }
        }
        public void RemoveGeneratedItemCustomMetadata(IVsProject project, List <string> paths)
        {
#if VS2017 || VS2019
            var projectDir = project.GetProjectBaseDirectory();
            project.UpdateProject((MSProject msproject) =>
            {
                var items = msproject.Xml.Items.Where(item =>
                {
                    if (item.ItemType.Equals("Compile") || item.ItemType.Equals("ClCompile") || item.ItemType.Equals("ClInclude"))
                    {
                        return(paths.Contains(Path.Combine(projectDir, item.Update)));
                    }
                    else
                    {
                        return(false);
                    }
                });

                foreach (var item in items)
                {
                    item.Parent.RemoveChild(item);
                }
            });
#endif
        }
        CheckGenerateFileIsValid(IVsProject project, string path)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var projectDir = project.GetProjectBaseDirectory();
            var dteproject = project.GetDTEProject();

            if (project.IsCSharpProject())
            {
                var fileset = GetCsharpGeneratedFiles(project, dteproject, projectDir, path);
                foreach (var source in fileset.sources.Keys)
                {
                    if (File.Exists(source))
                    {
                        const string message =
                            "A file named '{0}' already exists. If you want to add '{1}' first remove '{0}'.";

                        UIUtil.ShowErrorDialog("Ice Builder",
                                               string.Format(message,
                                                             FileUtil.RelativePath(projectDir, source),
                                                             FileUtil.RelativePath(projectDir, path)));
                        return(false);
                    }
                }
            }
            else
            {
                var fileset = GetCppGeneratedFiles(project, dteproject, ProjectFactoryHelperInstance.VCUtil, projectDir, path);

                foreach (var source in fileset.sources.Keys)
                {
                    if (File.Exists(source))
                    {
                        const string message =
                            "A file named '{0}' already exists. If you want to add '{1}' first remove '{0}' .";

                        UIUtil.ShowErrorDialog("Ice Builder",
                                               string.Format(message,
                                                             FileUtil.RelativePath(projectDir, source),
                                                             FileUtil.RelativePath(projectDir, path)));
                        return(false);
                    }
                }

                foreach (var header in fileset.headers.Keys)
                {
                    if (File.Exists(header))
                    {
                        const string message =
                            "A file named '{0}' already exists. If you want to add '{1}' first remove '{0}' .";

                        UIUtil.ShowErrorDialog("Ice Builder",
                                               string.Format(message,
                                                             FileUtil.RelativePath(projectDir, header),
                                                             FileUtil.RelativePath(projectDir, path)));
                        return(false);
                    }
                }
            }
            return(true);
        }
Esempio n. 4
0
        public static void DeleteItems(this IVsProject project, List <string> paths)
        {
            project.EnsureIsCheckout();
            var projectDir = project.GetProjectBaseDirectory();

            project.RemoveGeneratedItemCustomMetadata(paths);

            var sliceCompileDependencies = paths.Select(
                p =>
            {
                return(Path.Combine(Path.GetDirectoryName(p),
                                    string.Format("SliceCompile.{0}.d", Path.GetFileNameWithoutExtension(p))));
            }).Distinct().ToList();

            foreach (var path in sliceCompileDependencies)
            {
                if (File.Exists(path))
                {
                    try
                    {
                        File.Delete(path);
                    }
                    catch (IOException)
                    {
                    }
                }
            }
        }
Esempio n. 5
0
        CheckGenerateFileIsValid(IVsProject project, IceBuilderProjectType projectType, string path)
        {
            var projectDir = project.GetProjectBaseDirectory();
            var msproject  = project.GetMSBuildProject();

            if (projectType == IceBuilderProjectType.CsharpProjectType)
            {
                string outputDir       = GetDefaultOutputDir(msproject, true);
                string generatedSource = Path.Combine(projectDir, outputDir, 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)
            {
                var dteproject      = project.GetDTEProject();
                var outputDir       = GetDefaultOutputDir(msproject, false);
                var headerOutputDir = GetDefaultHeaderOutputDir(msproject, false);
                var source          = GetCppGeneratedSourceItemPath(msproject, path);
                var header          = GetCppGeneratedHeaderItemPath(msproject, path);

                foreach (EnvDTE.Configuration config in dteproject.ConfigurationManager)
                {
                    var evaluatedOutputDir       = Package.Instance.VCUtil.Evaluate(config, outputDir);
                    var evaluatedHeaderOutputDir = headerOutputDir.Equals(outputDir) ? evaluatedOutputDir :
                                                   Package.Instance.VCUtil.Evaluate(config, headerOutputDir);

                    string generatedSource = Path.GetFullPath(Path.Combine(projectDir, evaluatedOutputDir, source));
                    string generatedHeader = Path.GetFullPath(Path.Combine(projectDir, evaluatedHeaderOutputDir, header));

                    if (File.Exists(generatedSource) || File.Exists(generatedHeader))
                    {
                        const string message =
                            "A file named '{0}' or '{1}' already exists. If 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);
        }
        public static bool IsIceBuilderGeneratedItem(this IVsProject project, string path)
        {
            var projectDir   = project.GetProjectBaseDirectory();
            var includeValue = FileUtil.RelativePath(projectDir, path);

            return(project.WithProject((MSProject msproject) =>
            {
                return msproject.AllEvaluatedItems.FirstOrDefault(
                    item =>
                {
                    return (item.ItemType.Equals("Compile") ||
                            item.ItemType.Equals("ClCompile") ||
                            item.ItemType.Equals("ClInclude")) &&
                    item.EvaluatedInclude.Equals(includeValue) &&
                    item.HasMetadata("SliceCompileSource");
                }) != null;
            }));
        }
        public static void SetupGenerated(IVsProject project)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var projectDir = project.GetProjectBaseDirectory();

            //
            // Remove all CompileClCompile and ClInclude items that have an associted SliceCompileSource
            // item metadata that doesn't much any of the project SliceCompile items
            //
            if (project.IsCppProject())
            {
                project.DeleteItems(project.WithProject((MSProject msproject) =>
                {
                    var sliceCompile = msproject.AllEvaluatedItems.Where(
                        item => item.ItemType.Equals("SliceCompile")).Select(
                        item => item.EvaluatedInclude);

                    return(msproject.AllEvaluatedItems.Where(
                               item =>
                    {
                        if (item.ItemType.Equals("ClCompile") || item.ItemType.Equals("ClInclude"))
                        {
                            if (item.HasMetadata("SliceCompileSource"))
                            {
                                var value = item.GetMetadataValue("SliceCompileSource");
                                return !sliceCompile.Contains(value);
                            }
                        }
                        return false;
                    }).Select(item => Path.Combine(projectDir, item.EvaluatedInclude)).ToList());
                }));
            }
            else // C# project
            {
                project.DeleteItems(project.WithProject((MSProject msproject) =>
                {
                    var sliceCompile = msproject.AllEvaluatedItems.Where(
                        item => item.ItemType.Equals("SliceCompile")).Select(
                        item => item.EvaluatedInclude);

                    return(msproject.AllEvaluatedItems.Where(
                               item =>
                    {
                        if (item.ItemType.Equals("Compile"))
                        {
                            if (item.HasMetadata("SliceCompileSource"))
                            {
                                var value = item.GetMetadataValue("SliceCompileSource");
                                return !sliceCompile.Contains(value);
                            }
                        }
                        return false;
                    }).Select(item => Path.Combine(projectDir, item.EvaluatedInclude)).ToList());
                }));
            }

            // Now add any missing generated items
            var sliceItems = project.GetIceBuilderItems();

            foreach (var item in sliceItems)
            {
                AddGeneratedFiles(project, item);
            }
        }
        public static void AddCppGeneratedFiles(IVsProject project, string file)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var vcutil     = Package.Instance.VCUtil;
            var projectDir = project.GetProjectBaseDirectory();
            var dteproject = project.GetDTEProject();

            var fileset = GetCppGeneratedFiles(project, dteproject, vcutil, projectDir, file);

            var allConfigurations = new List <string>();

            foreach (EnvDTE.Configuration configuration in dteproject.ConfigurationManager)
            {
                allConfigurations.Add(ConfigurationString(configuration));
            }

            //
            // First remove any generated items that are not in the
            // current generated items set for this Slice file
            //
            project.DeleteItems(project.WithProject((MSProject msproject) =>
            {
                return(msproject.AllEvaluatedItems.Where(
                           item =>
                {
                    if (item.ItemType.Equals("ClCompile") && item.HasMetadata("SliceCompileSource"))
                    {
                        if (item.GetMetadataValue("SliceCompileSource").Equals(fileset.filename))
                        {
                            return !fileset.sources.ContainsKey(Path.GetFullPath(Path.Combine(projectDir, item.EvaluatedInclude)));
                        }
                    }
                    else if (item.ItemType.Equals("ClInclude") && item.HasMetadata("SliceCompileSource"))
                    {
                        if (item.GetMetadataValue("SliceCompileSource").Equals(fileset.filename))
                        {
                            return !fileset.headers.ContainsKey(Path.GetFullPath(Path.Combine(projectDir, item.EvaluatedInclude)));
                        }
                    }
                    return false;
                }).Select(item => Path.Combine(projectDir, item.EvaluatedInclude)).ToList());
            }));

            foreach (var entry in fileset.sources)
            {
                AddCppGeneratedItem(project, dteproject, vcutil,
                                    projectDir,
                                    FileUtil.RelativePath(projectDir, fileset.filename),
                                    FileUtil.RelativePath(projectDir, entry.Key),
                                    "Source Files",
                                    allConfigurations,
                                    entry.Value);
            }

            foreach (var entry in fileset.headers)
            {
                AddCppGeneratedItem(project, dteproject, vcutil,
                                    projectDir,
                                    FileUtil.RelativePath(projectDir, fileset.filename),
                                    FileUtil.RelativePath(projectDir, entry.Key), "Header Files", allConfigurations, entry.Value);
            }
        }