本文整理汇总了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();
}
}
}
示例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;
}
示例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);
}
示例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();
}
}
}