Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions src/Build.UnitTests/BackEnd/BuildManager_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4496,6 +4496,81 @@ public void GraphBuildShouldBeAbleToConstructGraphButSkipBuild()
logger.FullLog.ShouldContain("3 nodes, 2 edges");
}

[Fact]
public void GraphBuildSolutionIncludesSyntheticSolutionNodeInResults()
{
using TestEnvironment env = TestEnvironment.Create(_output);
ProjectCollection projectCollection = env.CreateProjectCollection().Collection;

TransientTestFolder root = env.CreateFolder(createFolder: true);
TransientTestFolder projectFolder = env.CreateFolder(Path.Combine(root.Path, "SimpleProject"), createFolder: true);
env.CreateFile(projectFolder, "SimpleProject.csproj",
"""
<Project>
<Target Name="Build">
<Message Text="ProjectBuilt" Importance="High" />
</Target>
</Project>
""");

TransientTestFile solutionFile = env.CreateFile(root, "SimpleProject.sln",
"""
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29326.124
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleProject", "SimpleProject\SimpleProject.csproj", "{79B5EBA6-5D27-4976-BC31-14422245A59A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{79B5EBA6-5D27-4976-BC31-14422245A59A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{79B5EBA6-5D27-4976-BC31-14422245A59A}.Debug|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
""");

env.CreateFile(root, $"after.{Path.GetFileName(solutionFile.Path)}.targets",
"""
<Project>
<Target Name="AfterSolutionHook" AfterTargets="Build">
<Message Text="AfterSolutionHookRan" Importance="High" />
</Target>
</Project>
""");

ProjectGraph graph = new(new ProjectGraphEntryPoint(solutionFile.Path), projectCollection);
graph.EntryPointNodes.Count.ShouldBe(1);
graph.ProjectNodes.Contains(graph.EntryPointNodes.Single()).ShouldBeFalse();

ProjectGraphNode syntheticSolutionNode = graph.EntryPointNodes.Single();

GraphBuildRequestData request = new(graph, Array.Empty<string>(), projectCollection.HostServices);

GraphBuildResult result = _buildManager.Build(_parameters, request);
result.OverallResult.ShouldBe(BuildResultCode.Success);

// ResultsByNode should include both project nodes AND the synthetic solution node
result.ResultsByNode.Count.ShouldBe(graph.ProjectNodes.Count + 1);
foreach (ProjectGraphNode graphNode in graph.ProjectNodes)
{
result.ResultsByNode.ContainsKey(graphNode).ShouldBeTrue();
}

// Verify synthetic solution node is included in results
result.ResultsByNode.ContainsKey(syntheticSolutionNode).ShouldBeTrue();
result.ResultsByNode[syntheticSolutionNode].OverallResult.ShouldBe(BuildResultCode.Success);

// Verify that both the project and solution hooks ran (addresses Rainer's review comment)
_logger.AssertLogContains("ProjectBuilt");
_logger.AssertLogContains("AfterSolutionHookRan");
}

/// <summary>
/// Helper task used by <see cref="TaskInputLoggingIsExposedToTasks"/> to verify <see cref="TaskLoggingHelper.IsTaskInputLoggingEnabled"/>.
/// </summary>
Expand Down
54 changes: 54 additions & 0 deletions src/Build.UnitTests/BinaryLogger_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,60 @@ public void BinaryLoggerShouldEmbedFilesWithRelativePathFromChildProjects()
generatedFileCount.ShouldBe(2, $"Embedded files: {string.Join(",", zipArchive.Entries)}");
}

[Fact]
public void BinaryLoggerGraphBuildSolutionEmbedsSolutionFile()
{
TransientTestFolder root = _env.CreateFolder(createFolder: true);
TransientTestFolder projectFolder = _env.CreateFolder(Path.Combine(root.Path, "SimpleProject"), createFolder: true);
_env.CreateFile(projectFolder, "SimpleProject.csproj",
"""
<Project>
<Target Name="Build">
<Message Text="ProjectBuilt" Importance="High" />
</Target>
</Project>
""");

TransientTestFile solutionFile = _env.CreateFile(root, "SimpleProject.sln",
"""
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29326.124
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleProject", "SimpleProject\SimpleProject.csproj", "{79B5EBA6-5D27-4976-BC31-14422245A59A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{79B5EBA6-5D27-4976-BC31-14422245A59A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{79B5EBA6-5D27-4976-BC31-14422245A59A}.Debug|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
""");

RunnerUtilities.ExecMSBuild(
$"\"{solutionFile.Path}\" /graphBuild /bl:\"{_logFile};ProjectImports=ZipFile\"",
out bool success);
success.ShouldBeTrue();

string projectImportsZipPath = Path.ChangeExtension(_logFile, ".ProjectImports.zip");
using var fileStream = new FileStream(projectImportsZipPath, FileMode.Open);
using var zipArchive = new ZipArchive(fileStream, ZipArchiveMode.Read);

string solutionFileName = Path.GetFileName(solutionFile.Path);
ZipArchiveEntry embeddedSolutionEntry = zipArchive.Entries
.FirstOrDefault(entry => entry.Name.Equals(solutionFileName, StringComparison.OrdinalIgnoreCase));

embeddedSolutionEntry.ShouldNotBeNull(
$"Expected solution file '{solutionFileName}' in project imports archive. Embedded files: {string.Join(",", zipArchive.Entries.Select(e => e.FullName))}");
embeddedSolutionEntry.Length.ShouldBeGreaterThan(0);
}

[RequiresSymbolicLinksFact]
public void BinaryLoggerShouldEmbedSymlinkFilesViaTaskOutput()
{
Expand Down
10 changes: 4 additions & 6 deletions src/Build.UnitTests/Graph/GraphLoadedFromSolution_tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -687,15 +687,13 @@ private void AssertSolutionBasedGraph(
// Exactly 1 node per project
graph.ProjectNodes.Count.ShouldBe(graph.ProjectNodes.Select(GetProjectPath).Distinct().Count());

// in the solution, all nodes are entry points
graphFromSolution.EntryPointNodes.Select(GetProjectPath)
.ShouldBeSetEquivalentTo(graph.ProjectNodes.Select(GetProjectPath));
graphFromSolution.EntryPointNodes.Count.ShouldBe(1);
graphFromSolution.EntryPointNodes.First().ProjectInstance.FullPath.ShouldBe(solutionPath);
graphFromSolution.GraphRoots.Count.ShouldBe(1);
graphFromSolution.GraphRoots.First().ProjectInstance.FullPath.ShouldBe(solutionPath);

if (projectConfigurations == null || graphFromSolution.ProjectNodes.All(n => n.ProjectReferences.Count == 0))
{
graphFromSolution.GraphRoots.Select(GetProjectPath)
.ShouldBeSameIgnoringOrder(graph.GraphRoots.Select(GetProjectPath));

graphFromSolution.ProjectNodes.Select(GetProjectPath)
.ShouldBeSameIgnoringOrder(graph.ProjectNodes.Select(GetProjectPath));
}
Expand Down
8 changes: 4 additions & 4 deletions src/Build.UnitTests/Graph/ProjectGraph_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -860,10 +860,10 @@ public void ConstructGraphWithSolution()
project8Xml.Save(project8Path);

var projectGraph = new ProjectGraph(slnFile.Path);
projectGraph.EntryPointNodes.Count.ShouldBe(5);
projectGraph.EntryPointNodes.Select(node => node.ProjectInstance.FullPath).ShouldBe(new[] { project1Path, project2Path, project3Path, project6Path, project8Path }, ignoreOrder: true);
projectGraph.GraphRoots.Count.ShouldBe(2);
projectGraph.GraphRoots.Select(node => node.ProjectInstance.FullPath).ShouldBe(new[] { project1Path, project6Path }, ignoreOrder: true);
projectGraph.EntryPointNodes.Count.ShouldBe(1);
projectGraph.EntryPointNodes.Single().ProjectInstance.FullPath.ShouldBe(slnFile.Path);
projectGraph.GraphRoots.Count.ShouldBe(1);
projectGraph.GraphRoots.Single().ProjectInstance.FullPath.ShouldBe(slnFile.Path);
projectGraph.ProjectNodes.Count.ShouldBe(7);

ProjectGraphNode project1Node = projectGraph.ProjectNodes.Single(node => node.ProjectInstance.FullPath == project1Path);
Expand Down
Loading
Loading