public void InvalidProjectsLogGoodInfo() { ProjectCreator projectA = ProjectCreator .Create(GetTempFileName()) .Import(@"$(Foo)\foo.props") .Save(); ProjectCreator dirsProj = ProjectCreator .Create(GetTempFileName()) .Property("IsTraversal", "true") .ItemInclude("ProjectFile", projectA.FullPath) .Save(); BuildEngine buildEngine = BuildEngine.Create(); MSBuildProjectLoader loader = new MSBuildProjectLoader(null, MSBuildToolsVersion, buildEngine); loader.LoadProjectsAndReferences(new[] { dirsProj.FullPath }); BuildErrorEventArgs errorEventArgs = buildEngine.ErrorEvents.ShouldHaveSingleItem(); errorEventArgs.Code.ShouldBe("MSB4019"); errorEventArgs.ColumnNumber.ShouldBe(3); errorEventArgs.HelpKeyword.ShouldBe("MSBuild.ImportedProjectNotFound"); errorEventArgs.LineNumber.ShouldBe(3); errorEventArgs.File.ShouldBe(projectA.FullPath); }
public void TraversalReferencesWork() { ProjectCreator projectB = ProjectCreator .Create(GetTempFileName()) .Save(); ProjectCreator projectA = ProjectCreator .Create(GetTempFileName()) .ItemProjectReference(projectB) .Save(); ProjectCreator dirsProj = ProjectCreator .Create(GetTempFileName()) .Property("IsTraversal", "true") .ItemInclude("ProjectFile", projectA.FullPath) .Save(); BuildEngine buildEngine = BuildEngine.Create(); MSBuildProjectLoader loader = new MSBuildProjectLoader(null, MSBuildToolsVersion, buildEngine); ProjectCollection projectCollection = loader.LoadProjectsAndReferences(new[] { dirsProj.FullPath }); projectCollection.LoadedProjects.Select(i => i.FullPath).ShouldBe( new[] { dirsProj.FullPath, projectA.FullPath, projectB.FullPath }, ignoreOrder: true); }
public void InvalidProjectsLogGoodInfo() { var projectA = ProjectBuilder .Create() .AddImport(new Import(@"$(Foo)\foo.props")) .Save(GetTempFileName()); var dirsProj = ProjectBuilder .Create() .AddProperty("IsTraversal=true") .AddItem($"ProjectFile={projectA.FullPath}") .Save(GetTempFileName()); MSBuildProjectLoader loader = new MSBuildProjectLoader(null, MSBuildToolsVersion, Log); loader.LoadProjectsAndReferences(new[] { dirsProj.FullPath }); var errorEventArgs = _buildEngine.Errors.ShouldHaveSingleItem(); errorEventArgs.Code.ShouldBe("MSB4019"); errorEventArgs.ColumnNumber.ShouldBe(3); errorEventArgs.HelpKeyword.ShouldBe("MSBuild.ImportedProjectNotFound"); errorEventArgs.LineNumber.ShouldBe(3); errorEventArgs.File.ShouldBe(projectA.FullPath); }
public bool Execute(string file, string projectsFile, string msBuildVersion, bool requireConsent, bool disableParallelProcessing, string[] fallbackSources, bool noCache, string packageSaveMode, string[] sources, string configFile, bool nonInteractive, string verbosity, int timeout, string toolPath, bool enableOptimization, string markerPath, string[] inputs, string msbuildToolsVersion, string project, string globalProperties, string msbuildPath, string additionalArguments) { if (BuildEngine == null) { BuildEngine = new CBTBuildEngine(); } MSBuildToolsVersion = msbuildToolsVersion; Project = project; GlobalProperties = globalProperties; File = file; FileInfo projectsFileInfo = !String.IsNullOrWhiteSpace(projectsFile) ? new FileInfo(projectsFile) : null; inputs = inputs.Concat(GetAllPathsFromProjectsFile(projectsFileInfo)).ToArray(); if (enableOptimization && IsFileUpToDate(Log, markerPath, inputs)) { Log.LogMessage(MessageImportance.Low, "Traversal NuGet packages are up-to-date"); return(true); } MSBuildProjectLoader projectLoader = new MSBuildProjectLoader(GlobalProperties.Split(new[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries).Where(i => !String.IsNullOrWhiteSpace(i)).Select(i => i.Trim().Split(new[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries)).ToDictionary(i => i.First(), i => i.Last()), MSBuildToolsVersion, Log, ProjectLoadSettings.IgnoreMissingImports); Log.LogMessage(MessageImportance.Normal, $"Loading project references for '{Project}'..."); _projectCollection = projectLoader.LoadProjectsAndReferences(new[] { Project }); _enableOptimization = enableOptimization; Log.LogMessage(MessageImportance.Low, "10 Slowest Loading Projects:"); foreach (var loadTimes in projectLoader.Statistics.ProjectLoadTimes.OrderByDescending(i => i.Value).Take(10)) { Log.LogMessage(MessageImportance.Low, $" {loadTimes.Key} {loadTimes.Value}"); } if (Log.HasLoggedErrors) { return(false); } Log.LogMessage(MessageImportance.Normal, $"Loaded '{_projectCollection.LoadedProjects.Count}' projects"); if (!TryWriteSolutionFile(_projectCollection)) { return(false); } if (projectsFileInfo != null && !TryWriteProjectsFile(_projectCollection, projectsFileInfo)) { return(false); } bool ret = Execute(file, msBuildVersion, requireConsent, disableParallelProcessing, fallbackSources, noCache, packageSaveMode, sources, configFile, nonInteractive, verbosity, timeout, toolPath, enableOptimization, markerPath, inputs, msbuildPath, additionalArguments); return(ret && !Log.HasLoggedErrors); }
public void BuildFailsIfError() { ProjectCreator dirsProj = ProjectCreator .Create(GetTempFileName()) .Property("IsTraversal", "true") .ItemInclude("ProjectFile", "does not exist") .Save(); BuildEngine buildEngine = BuildEngine.Create(); MSBuildProjectLoader loader = new MSBuildProjectLoader(null, MSBuildToolsVersion, buildEngine); loader.LoadProjectsAndReferences(new[] { dirsProj.FullPath }); buildEngine.Errors.ShouldHaveSingleItem().ShouldStartWith("The project file could not be loaded. Could not find file "); }
public void ProjectReferencesWork() { var projectB = ProjectBuilder.Create() .Save(GetTempFileName()); var projectA = ProjectBuilder .Create() .AddProjectReference(projectB) .Save(GetTempFileName()); MSBuildProjectLoader loader = new MSBuildProjectLoader(null, MSBuildToolsVersion, Log); ProjectCollection projectCollection = loader.LoadProjectsAndReferences(new[] { projectA.FullPath }); projectCollection.LoadedProjects.Select(i => i.FullPath).ShouldBe(new[] { projectA.FullPath, projectB.FullPath }); }
public void GlobalPropertiesSetCorrectly() { Dictionary <string, string> expectedGlobalProperties = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { "Property1", "1A836FEB3ABA43B183034DFDD5C4E375" }, { "Property2", "CEEC5C9FF0F344DAA32A0F545460EB2C" } }; var projectA = ProjectBuilder .Create() .Save(GetTempFileName()); MSBuildProjectLoader loader = new MSBuildProjectLoader(expectedGlobalProperties, MSBuildToolsVersion, Log); ProjectCollection projectCollection = loader.LoadProjectsAndReferences(new[] { projectA.FullPath }); projectCollection.GlobalProperties.ShouldBe(expectedGlobalProperties); }
public void ProjectReferencesWork() { ProjectCreator projectB = ProjectCreator .Create(GetTempFileName()) .Save(); ProjectCreator projectA = ProjectCreator .Create(GetTempFileName()) .ItemProjectReference(projectB) .Save(); BuildEngine buildEngine = BuildEngine.Create(); MSBuildProjectLoader loader = new MSBuildProjectLoader(null, MSBuildToolsVersion, buildEngine); ProjectCollection projectCollection = loader.LoadProjectsAndReferences(new[] { projectA.FullPath }); projectCollection.LoadedProjects.Select(i => i.FullPath).ShouldBe(new[] { projectA.FullPath, projectB.FullPath }); }
public void GlobalPropertiesSetCorrectly() { Dictionary <string, string> expectedGlobalProperties = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { ["Property1"] = "1A836FEB3ABA43B183034DFDD5C4E375", ["Property2"] = "CEEC5C9FF0F344DAA32A0F545460EB2C", }; ProjectCreator projectA = ProjectCreator .Create(GetTempFileName()) .Save(); BuildEngine buildEngine = BuildEngine.Create(); MSBuildProjectLoader loader = new MSBuildProjectLoader(expectedGlobalProperties, ProjectCollection.GlobalProjectCollection.DefaultToolsVersion, buildEngine); ProjectCollection projectCollection = loader.LoadProjectsAndReferences(new[] { projectA.FullPath }); projectCollection.GlobalProperties.ShouldBe(expectedGlobalProperties); }
private ProjectCollection LoadProjectsAndReferences(IDictionary <string, string> globalProperties) { // Create an MSBuildProject loader with the same global properties of the project that requested a solution file MSBuildProjectLoader projectLoader = new MSBuildProjectLoader(globalProperties, ToolsVersion, BuildEngine, ProjectLoadSettings.IgnoreMissingImports) { CollectStats = CollectStats }; LogMessageHigh("Loading project references..."); ProjectCollection projectCollection = projectLoader.LoadProjectsAndReferences(ProjectReferences.Select(i => i.GetMetadata("FullPath")).Concat(new[] { ProjectFullPath })); LogMessageNormal($"Loaded {projectCollection.LoadedProjects.Count} project(s)"); if (CollectStats) { LogStatistics(projectLoader); } return(projectCollection); }
public void BuildFailsIfError() { var dirsProj = ProjectBuilder .Create() .AddProperty("IsTraversal=true") .AddItem("ProjectFile=does not exist") .Save(GetTempFileName()); MSBuildProjectLoader loader = new MSBuildProjectLoader(null, MSBuildToolsVersion, Log); loader.LoadProjectsAndReferences(new[] { dirsProj.FullPath }); Log.HasLoggedErrors.ShouldBe(true); _buildEngine.LoggedEvents.Count.ShouldBe(1); BuildErrorEventArgs errorEvent = _buildEngine.LoggedEvents.FirstOrDefault() as BuildErrorEventArgs; errorEvent.ShouldNotBeNull(); errorEvent?.Message.ShouldStartWith("The project file could not be loaded. Could not find file "); }
public void TraversalReferencesWork() { var projectB = ProjectBuilder.Create() .Save(GetTempFileName()); var projectA = ProjectBuilder .Create() .AddProjectReference(projectB) .Save(GetTempFileName()); var dirsProj = ProjectBuilder .Create() .AddProperty("IsTraversal=true") .AddItem($"ProjectFile={projectA.FullPath}") .Save(GetTempFileName()); MSBuildProjectLoader loader = new MSBuildProjectLoader(null, MSBuildToolsVersion, Log); ProjectCollection projectCollection = loader.LoadProjectsAndReferences(new[] { dirsProj.FullPath }); projectCollection.LoadedProjects.Select(i => i.FullPath).ShouldBe(new[] { dirsProj.FullPath, projectA.FullPath, projectB.FullPath }); }