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


C# ProjectCollection.Dispose方法代码示例

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


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

示例1: GenerateProjectFile

        private void GenerateProjectFile()
        {
            var projectExtension = Path.GetExtension(ProjectFilePath);
            if (!File.Exists(ProjectFilePath) ||
                ".dll".Equals(projectExtension, StringComparison.OrdinalIgnoreCase) ||
                ".winmd".Equals(projectExtension, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            ProjectCollection projectCollection = null;

            try
            {
                var title = Path.GetFileName(ProjectFilePath);
                var destinationFileName = Path.Combine(ProjectDestinationFolder, title) + ".html";

                AddDeclaredSymbolToRedirectMap(SymbolIDToListOfLocationsMap, SymbolIdService.GetId(title), title, 0);

                // ProjectCollection caches the environment variables it reads at startup
                // and doesn't re-get them later. We need a new project collection to read
                // the latest set of environment variables.
                projectCollection = new ProjectCollection();
                this.msbuildProject = new Project(
                    ProjectFilePath,
                    null,
                    null,
                    projectCollection,
                    ProjectLoadSettings.IgnoreMissingImports);

                var msbuildSupport = new MSBuildSupport(this);
                msbuildSupport.Generate(ProjectFilePath, destinationFileName, msbuildProject, true);

                GenerateXamlFiles(msbuildProject);

                GenerateTypeScriptFiles(msbuildProject);

                OtherFiles.Add(title);
            }
            catch (Exception ex)
            {
                Log.Exception("Exception during Project file generation: " + ProjectFilePath + "\r\n" + ex.ToString());
            }
            finally
            {
                if (projectCollection != null)
                {
                    projectCollection.UnloadAllProjects();
                    projectCollection.Dispose();
                }
            }
        }
开发者ID:rgmills,项目名称:SourceBrowser,代码行数:52,代码来源:ProjectGenerator.ProjectFile.cs

示例2: foreach


//.........这里部分代码省略.........
                    DataCollection.CommentMarkProfile(8800, "Pending Build Request from MSBuild.exe");
#endif
                    BuildResult results = null;
                    buildManager.BeginBuild(parameters);
                    Exception exception = null;
                    try
                    {
                        try
                        {
                            lock (s_buildLock)
                            {
                                s_activeBuild = buildManager.PendBuildRequest(request);

                                // Even if Ctrl-C was already hit, we still pend the build request and then cancel.
                                // That's so the build does not appear to have completed successfully.
                                if (s_receivedCancel == 1)
                                {
                                    buildManager.CancelAllSubmissions();
                                }
                            }

                            results = s_activeBuild.Execute();
                        }
                        finally
                        {
                            buildManager.EndBuild();
                        }
                    }
                    catch (Exception ex)
                    {
                        exception = ex;
                        success = false;
                    }

                    if (results != null && exception == null)
                    {
                        success = results.OverallResult == BuildResultCode.Success;
                        exception = results.Exception;
                    }

                    if (exception != null)
                    {
                        success = false;

                        // InvalidProjectFileExceptions have already been logged.
                        if (exception.GetType() != typeof(InvalidProjectFileException))
                        {
                            if
                                (
                                exception.GetType() == typeof(LoggerException) ||
                                exception.GetType() == typeof(InternalLoggerException)
                                )
                            {
                                // We will rethrow this so the outer exception handler can catch it, but we don't
                                // want to log the outer exception stack here.
                                throw exception;
                            }

                            if (exception.GetType() == typeof(BuildAbortedException))
                            {
                                // this is not a bug and should not dump stack. It will already have been logged
                                // appropriately, there is no need to take any further action with it.
                            }
                            else
                            {
                                // After throwing again below the stack will be reset. Make certain we log everything we 
                                // can now
                                Console.WriteLine(AssemblyResources.GetString("FatalError"));
#if DEBUG
                                Console.WriteLine("This is an unhandled exception in MSBuild -- PLEASE OPEN A BUG AGAINST THE MSBUILD TEAM.");
#endif
                                Console.WriteLine(exception.ToString());
                                Console.WriteLine();

                                throw exception;
                            }
                        }
                    }
                }
            }
            // handle project file errors
            catch (InvalidProjectFileException ex)
            {
                // just eat the exception because it has already been logged
                ErrorUtilities.VerifyThrow(ex.HasBeenLogged, "Should have been logged");
                success = false;
            }
            finally
            {
                FileUtilities.ClearCacheDirectory();
                if (projectCollection != null)
                {
                    projectCollection.Dispose();
                }

                BuildManager.DefaultBuildManager.Dispose();
            }

            return success;
        }
开发者ID:assafnativ,项目名称:msbuild,代码行数:101,代码来源:XMake.cs

示例3: Generate

        /// <summary>
        /// Generates the solution file with the specified amount of space remaining relative
        /// to MAX_PATH.
        /// </summary>
        /// <param name="solutionName">The solution name to be created</param>
        /// <param name="pathSpaceRemaining">The amount of path space remaining, or -1 to generate normally</param>
        /// <param name="toGenerate">The projects to be incldued in the generated solution</param>
        /// <returns></returns>
        public static SolutionFile Generate(string solutionName, int pathSpaceRemaining, params ISolutionElement[] toGenerate) {
            List<MSBuild.Project> projects = new List<MSBuild.Project>();
            var location = TestData.GetTempPath(randomSubPath: true);

            if (pathSpaceRemaining >= 0) {
                int targetPathLength = 260 - pathSpaceRemaining;
                location = location + new string('X', targetPathLength - location.Length);
            }
            System.IO.Directory.CreateDirectory(location);

            MSBuild.ProjectCollection collection = new MSBuild.ProjectCollection();
            foreach (var project in toGenerate) {
                projects.Add(project.Save(collection, location));
            }

#if DEV10
            StringBuilder slnFile = new StringBuilder("\r\nMicrosoft Visual Studio Solution File, Format Version 11.00\r\n\u0023 Visual Studio 2010\r\n");
#elif DEV11
            StringBuilder slnFile = new StringBuilder("\r\nMicrosoft Visual Studio Solution File, Format Version 12.00\r\n\u0023 Visual Studio 2012\r\n");
#elif DEV12
            StringBuilder slnFile = new StringBuilder("\r\nMicrosoft Visual Studio Solution File, Format Version 12.00\r\n\u0023 Visual Studio 2013\r\nVisualStudioVersion = 12.0.20827.3\r\nMinimumVisualStudioVersion = 10.0.40219.1\r\n");
#elif DEV14
            StringBuilder slnFile = new StringBuilder("\r\nMicrosoft Visual Studio Solution File, Format Version 12.00\r\n\u0023 Visual Studio 2015\r\nVisualStudioVersion = 14.0.22230.0\r\nMinimumVisualStudioVersion = 10.0.40219.1\r\n");
#elif DEV15
            StringBuilder slnFile = new StringBuilder("\r\nMicrosoft Visual Studio Solution File, Format Version 12.00\r\n\u0023 Visual Studio 2015\r\nVisualStudioVersion = 15.0.30000.0\r\nMinimumVisualStudioVersion = 10.0.40219.1\r\n");
#else
#error Unsupported VS version
#endif
            for (int i = 0; i < projects.Count; i++) {
                if (toGenerate[i].Flags.HasFlag(SolutionElementFlags.ExcludeFromSolution)) {
                    continue;
                }

                var project = projects[i];
                var projectTypeGuid = toGenerate[i].TypeGuid;

                slnFile.AppendFormat(@"Project(""{0:B}"") = ""{1}"", ""{2}"", ""{3:B}""
EndProject
", projectTypeGuid,
 project != null ? Path.GetFileNameWithoutExtension(project.FullPath) : toGenerate[i].Name,
 project != null ? CommonUtils.GetRelativeFilePath(location, project.FullPath): toGenerate[i].Name,
 project != null ? Guid.Parse(project.GetProperty("ProjectGuid").EvaluatedValue) : Guid.NewGuid());
            }
            slnFile.Append(@"Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Release|Any CPU = Release|Any CPU
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
");
            for (int i = 0; i < projects.Count; i++) {
                if (toGenerate[i].Flags.HasFlag(SolutionElementFlags.ExcludeFromConfiguration)) {
                    continue;
                }

                var project = projects[i];
                slnFile.AppendFormat(@"		{0:B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {0:B}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {0:B}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {0:B}.Release|Any CPU.Build.0 = Release|Any CPU
", Guid.Parse(project.GetProperty("ProjectGuid").EvaluatedValue));
            }

            slnFile.Append(@"	EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
EndGlobal
");

            collection.UnloadAllProjects();
            collection.Dispose();

            var slnFilename = Path.Combine(location, solutionName + ".sln");
            File.WriteAllText(slnFilename, slnFile.ToString(), Encoding.UTF8);
            return new SolutionFile(slnFilename, toGenerate);
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:85,代码来源:SolutionFile.cs

示例4: GenerateProjectFile

        public void GenerateProjectFile()
        {
            var projectExtension = Path.GetExtension(ProjectFilePath);
            if (!File.Exists(ProjectFilePath) ||
                ".dll".Equals(projectExtension, StringComparison.OrdinalIgnoreCase) ||
                ".winmd".Equals(projectExtension, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            ProjectCollection projectCollection = null;

            try
            {
                var title = Path.GetFileName(ProjectFilePath);
                projectCollection = new ProjectCollection();

                GenerateMsBuildProject(projectCollection);
                ExtendGenerator.GenerateConfig(this, msbuildProject); // .config

                if (Configuration.ProcessContent)
                {
                    // process content files
                    GenerateXamlFiles(msbuildProject);  // .xaml

                    GenerateTypeScriptFiles(msbuildProject);   // .ts

                    ExtendGenerator.GenerateContentFiles(this, msbuildProject); // .md, .cshtml, .aspx, .xml, .xslt, .json, .sql
                }

                OtherFiles.Add(title);
            }
            catch (Exception ex)
            {
                Log.Exception("Exception during Project file generation: " + ProjectFilePath + "\r\n" + ex.ToString());
            }
            finally
            {
                if (projectCollection != null)
                {
                    projectCollection.UnloadAllProjects();
                    projectCollection.Dispose();
                }
            }
        }
开发者ID:akrisiun,项目名称:SourceBrowser,代码行数:45,代码来源:ProjectGenerator.ProjectFile.cs


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