public void StaticGraphBuildsSucceed(string projectExtension) { ProjectCreator sdkReference = ProjectCreator.Templates.SdkCsproj( Path.Combine(TestRootPath, "sdkstyle", "sdkstyle.csproj"), targetFramework: "net472") .Save(); ProjectCreator legacyReference = ProjectCreator.Templates.LegacyCsproj( Path.Combine(TestRootPath, "legacy", "legacy.csproj"), targetFrameworkVersion: "v4.7.2") .Save(); ProjectCreator noTargets = ProjectCreator.Templates.NoTargetsProject( path: Path.Combine(TestRootPath, "notargets", "notargets.csproj"), targetFramework: "net472", customAction: creator => { creator.ItemProjectReference(sdkReference, referenceOutputAssembly: false); creator.ItemProjectReference(legacyReference, referenceOutputAssembly: false); }).Save(); ProjectCreator project = ProjectCreator.Templates.SdkCsproj( Path.Combine(TestRootPath, "main", $"main{projectExtension}"), targetFramework: "net472", projectCreator: creator => { creator.ItemProjectReference(noTargets, referenceOutputAssembly: false); }) .Save() .TryBuild("Restore", out bool result, out BuildOutput restoreOutput); result.ShouldBeTrue(restoreOutput.GetConsoleLog()); using (BuildManager buildManager = new BuildManager()) using (ProjectCollection projectCollection = new ProjectCollection()) { try { BuildOutput buildOutput = BuildOutput.Create(); buildManager.BeginBuild( new BuildParameters(projectCollection) { Loggers = new[] { buildOutput }, IsolateProjects = true, }); GraphBuildResult graphResult = buildManager.BuildRequest( new GraphBuildRequestData( new[] { new ProjectGraphEntryPoint(project.FullPath) }, new[] { "Build" })); graphResult.OverallResult.ShouldBe(BuildResultCode.Success, buildOutput.GetConsoleLog()); } finally { buildManager.EndBuild(); } } }
public void CanUseNuGetSdkResolver() { using (ProjectCollection projectCollection = new ProjectCollection()) { BuildOutput buildOutput = BuildOutput.Create(); projectCollection.RegisterLogger(buildOutput); using (PackageRepository.Create(TestRootPath) .Package("Foo.Bar", "1.2.3", out Package package) .FileText(Path.Combine("Sdk", "Sdk.props"), "<Project />") .FileText(Path.Combine("Sdk", "Sdk.targets"), "<Project />")) { ProjectCreator projectCreator = ProjectCreator .Create( sdk: $"{package.Id}/{package.Version}", projectCollection: projectCollection) .Save(GetTempFileName(".csproj")); try { Project unused = projectCreator.Project; } catch (Exception e) { throw new Exception(buildOutput.GetConsoleLog(), e); } } } }
public void ConsoleLog() { BuildOutput buildOutput = GetProjectLoggerWithEvents(eventSource => { eventSource.OnErrorRaised("FDC8FB4F8E084055974580DF7CD7531E", "6496288436BE4E7CAE014F163914063C", "7B07B020E38343A89B3FA844A40895E4", 1, 2, 0, 0); eventSource.OnWarningRaised("E00BBDAEEFAB45949AFEE1BF792B1691", "56206897E63F44159603D22BB7C08145", "C455F26F4D4543E78F109BCB00F02BE2", 1, 2, 0, 0); eventSource.OnMessageRaised("55B991507D52403295E92E4FFA8704F3", MessageImportance.High); eventSource.OnMessageRaised("FA7FCCBE43B741998BAB399E74F2997D"); eventSource.OnMessageRaised("67C0E0E52F2A45A981F3143BAF00A4A3", MessageImportance.Low); }); buildOutput.GetConsoleLog() #pragma warning disable SA1116 // Split parameters must start on line after declaration .ShouldBe(@"7B07B020E38343A89B3FA844A40895E4(1,2): error 6496288436BE4E7CAE014F163914063C: FDC8FB4F8E084055974580DF7CD7531E C455F26F4D4543E78F109BCB00F02BE2(1,2): warning 56206897E63F44159603D22BB7C08145: E00BBDAEEFAB45949AFEE1BF792B1691 55B991507D52403295E92E4FFA8704F3 FA7FCCBE43B741998BAB399E74F2997D ", #pragma warning restore SA1116 // Split parameters must start on line after declaration StringCompareShould.IgnoreLineEndings); }