当前位置: 首页>>代码示例>>C#>>正文


C# Solution.GetProjects方法代码示例

本文整理汇总了C#中Solution.GetProjects方法的典型用法代码示例。如果您正苦于以下问题:C# Solution.GetProjects方法的具体用法?C# Solution.GetProjects怎么用?C# Solution.GetProjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Solution的用法示例。


在下文中一共展示了Solution.GetProjects方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Configure

        /// <summary>
        /// Sets up a solution level custom dictionary and links all project to it
        /// </summary>
        /// <param name="solution">The solution object</param>
        /// <param name="buildFolderPath">The folder to store the dictionary file</param>
        public static void Configure(Solution solution, string buildFolderPath)
        {
            // Add file if missing (should not overwrite per solution changes)
            var dictionaryFilePath = Path.Combine(buildFolderPath, DictionaryFileName);
            if (!File.Exists(dictionaryFilePath))
            {
                File.WriteAllText(dictionaryFilePath, RS.CustomDictionary);
            }

            // Make every project link to this dictionary
            foreach (var project in solution.GetProjects().Select(x => x.AsMSBuildProject()).Where(x => x != null))
            {
                // find the first dictionary elements
                var dictionaryRelativePath = project.DirectoryPath.GetRelativePath(dictionaryFilePath);
                var codeAnalysisDictionaryItems = project.GetItems("CodeAnalysisDictionary");
                if (codeAnalysisDictionaryItems != null && codeAnalysisDictionaryItems.Count != 0)
                {
                    // update existing dictionary links, useful if project folder structures change
                    foreach (var item in codeAnalysisDictionaryItems)
                    {
                        item.Xml.Include = dictionaryRelativePath;
                    }
                }
                else
                {
                    var newCompile = project.Xml.AddItem("CodeAnalysisDictionary", dictionaryRelativePath);
                    newCompile.AddMetadata("Link", DictionaryFileName);
                }
            }
        }
开发者ID:matt40k,项目名称:VSAutomate,代码行数:35,代码来源:CustomDictionary.cs

示例2: Configure

        /// <summary>
        /// Sets up a default solution level stylecop.settings file, 
        /// then creates project level settings file for every proect that
        /// link to the solution level settings
        /// </summary>
        /// <param name="solution">the solution folder</param>
        /// <param name="buildFolderPath">the folder to store the solution stylecop.settings</param>
        /// <param name="companyName"></param>
        public static void Configure(Solution solution, string buildFolderPath, string companyName)
        {
            // Solution settings are copied if new but not overwritten
            var solutionSettingsPath = Path.Combine(buildFolderPath, SettingsFileName);
            if (!File.Exists(solutionSettingsPath))
            {
                File.WriteAllText(solutionSettingsPath, string.Format(RS.settings_stylecop_solution, CultureInfo.CurrentCulture, companyName));
            }

            // project settings are always linked to solution settings so should be copied if edited
            foreach (var project in solution.GetProjects())
            {
                // work out the project settings.stylecop filePath relative to the solution settings file
                var projDirectory = project.FullName.GetDirectory();
                var projectSettingsPath = Path.Combine(projDirectory, SettingsFileName);
                var relativePathToSolutionSettings = projDirectory.GetRelativePath(solutionSettingsPath);

                // check the hash, if it matches don't replace, otherwise, create or overwrite
                var stylecopProjectFileText = string.Format(RS.settings_stylecop_project, relativePathToSolutionSettings);
                var expectedFileHash = FileExtensions.GetFileHash(stylecopProjectFileText);
                if (!File.Exists(projectSettingsPath) || !FileExtensions.GetFileHash(projectSettingsPath).SequenceEqual(expectedFileHash))
                {
                    File.WriteAllText(projectSettingsPath, stylecopProjectFileText);
                }
            }
        }
开发者ID:matt40k,项目名称:VSAutomate,代码行数:34,代码来源:StylecopSettings.cs

示例3: Configure

        /// <summary>
        /// Sets up a globalassemblyinfo file in the solution root and links this to all solution projects
        /// </summary>
        /// <param name="solution">The solution object</param>
        /// <param name="companyName">The company name to add in the GlobalAssemblyInfo</param>
        public static void Configure(Solution solution, string companyName)
        {
            // Adds a globalassemblyinfo file to a solution directory and links it to all projects
            var globalFilePath = Path.Combine(solution.GetDirectory(), GlobalFileName);

            if (!File.Exists(globalFilePath))
            {
                var fileText = RS.GlobalAssemblyInfo;
                var formattedFileText = string.Format(fileText, solution.GetName(), "[Enter description]", companyName, DateTime.Today.Year, CultureInfo.CurrentCulture);
                File.WriteAllText(globalFilePath, formattedFileText);
            }

            foreach (var project in solution.GetProjects())
            {
                project.AddLinkItem("compile", project.GetDirectory().GetRelativePath(globalFilePath), "Properties\\" + GlobalFileName);
            }
        }
开发者ID:matt40k,项目名称:VSAutomate,代码行数:22,代码来源:GlobalAssemblyInfo.cs

示例4: Configure

        // TODO refactor this
        public static void Configure(Solution solution, string toolsPath)
        {
            // if projects contains app.config, we should have one nested transform file per build configuration
            // app.config build action should be TransformOnBuild and config transform import target should be
            // added to project
            var solutionConfigNames = solution.SolutionBuild.SolutionConfigurations.Cast<SolutionConfiguration>().Select(x => x.Name).ToArray();
            var transformMetadata = "TransformOnBuild";

            foreach (var project in solution.GetProjects().Select(x => x.AsMSBuildProject()).Where(x => x != null))
            {
                var targetPath = Path.Combine(toolsPath, "net45", "targets", TransformFileName);
                var targetRelativePath = project.DirectoryPath.GetRelativePath(targetPath);

                // any app.configs in project?
                var allItems = project.AllEvaluatedItems.ToList();
                var configs = allItems.Where(x => x.Xml.Include.Equals("app.config", StringComparison.InvariantCultureIgnoreCase) || x.Xml.Include.EndsWith("\\app.config", StringComparison.InvariantCultureIgnoreCase)).ToList();
                if (!configs.Any()) continue;

                foreach (var config in configs)
                {
                    // add transform command to app config if not already there
                    if (config.Xml.Metadata.Any(x => x.Name.Equals(transformMetadata)))
                        config.Xml.AddMetadata(transformMetadata, "True");

                    // create transforms for each config
                    foreach (var solutionConfig in solutionConfigNames)
                    {
                        var configFileName = Path.GetFileName(config.Xml.Include);
                        var configTransformFileName = configFileName.Replace(".", $".{solutionConfig}.");
                        var transform = allItems.Single(x => x.Xml.Include.Equals(configTransformFileName, StringComparison.InvariantCultureIgnoreCase));
                        if (transform == null)
                        {
                            // Add transform, creates a new file if one doesn't exist
                            var transformFilePath = Path.Combine(project.DirectoryPath, configTransformFileName);
                            if (!File.Exists(TransformFileName)) File.WriteAllText(transformFilePath, @"<?xml version=""1.0"" encoding=""utf - 8""?>");
                            project.AddItem("None", configTransformFileName, new[] { new KeyValuePair<string, string>("DependentUpon", "configFileName"), });
                        }
                    }
                }

                // sort out msbuild import which transforms the files on build
                ConfigProjectImport(project, targetRelativePath, TransformFileName);
            }
        }
开发者ID:matt40k,项目名称:VSAutomate,代码行数:45,代码来源:AppConfigTransform.cs

示例5: Configure

        /// <summary>
        /// Sets up a solution level code analysis ruleset and links all solution projects to it
        /// </summary>
        /// <param name="solution">The solution object</param>
        /// <param name="buildFolderPath">The folder to store the ruleset file</param>
        public static void Configure(Solution solution, string buildFolderPath)
        {
            // Add file if missing (should not overwrite per solution changes)
            var rulesetFile = Path.Combine(buildFolderPath, SettingsFileName);
            if (!File.Exists(rulesetFile))
            {
                File.WriteAllText(rulesetFile, RS.Default_ruleset);
            }
            
            foreach (var project in solution.GetProjects().Select(x => x.AsMSBuildProject()).Where(x => x != null))
            {
                // strip out additional codeanalysis settings that we never need
                var propertyGroups = project.Xml.PropertyGroups.ToList();
                foreach (var prop in propertyGroups.SelectMany(group => group.Properties.Where(x => ExtraSettings.Contains(x.Name))))
                {
                    prop.Value = string.Empty;
                }
                
                // ignore code analysis on generated code for all build configurations
                var buildConfigProps = propertyGroups.Where(x => x.Condition.Contains("$(Configuration)|$(Platform)"));
                foreach (var prop in buildConfigProps)
                {
                    prop.AddOrSetProperty("CodeAnalysisIgnoreGeneratedCode", true);
                }

                // link all projects to solution ruleset
                foreach (var prop in buildConfigProps)
                {
                    prop.AddOrSetProperty("CodeAnalysisRuleSet", project.DirectoryPath.GetRelativePath(rulesetFile));
                }
                
                // enforce code analysis for all projects
                foreach (var prop in buildConfigProps)
                {
                    prop.AddOrSetProperty("RunCodeAnalysis", true);
                }
            }
        }
开发者ID:matt40k,项目名称:VSAutomate,代码行数:43,代码来源:AnalysisRuleset.cs

示例6: Configure

        /// <summary>
        /// Sets up solution build configurations and ensure they exist across all projects
        /// </summary>
        /// <param name="solution">The solution object</param>
        public static void Configure(Solution solution)
        {
            try
            {
                // ensure solution level build configs for development, staging and release
                var solutionConfigs = solution.SolutionBuild.SolutionConfigurations;

                // change your default configurations here
                foreach (var configName in new[] { "Development", "Staging", "Release" })
                {
                    var copyFrom = configName != "release" ? "debug" : "release";
                    var config = solutionConfigs.ByName(configName) ?? solutionConfigs.Add(configName, copyFrom, true);

                    foreach (var project in solution.GetProjects())
                    {
                        project.ConfigurationManager?.AddOrUpdate(config, copyFrom);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.Write("SolutionBuildConfig.Configure() threw an exception {0}", e);
            }
        }
开发者ID:matt40k,项目名称:VSAutomate,代码行数:28,代码来源:SolutionBuildConfig.cs


注:本文中的Solution.GetProjects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。