From e2ebae35151861f293becc362b7f9facd55ddce2 Mon Sep 17 00:00:00 2001 From: Jenny Bai Date: Tue, 15 Oct 2024 15:10:21 +0800 Subject: [PATCH 1/8] Add EmbeddedResources for CompileDependencyCache --- src/Tasks/Microsoft.Common.CurrentVersion.targets | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Tasks/Microsoft.Common.CurrentVersion.targets b/src/Tasks/Microsoft.Common.CurrentVersion.targets index b7e42801af8..27e477d539d 100644 --- a/src/Tasks/Microsoft.Common.CurrentVersion.targets +++ b/src/Tasks/Microsoft.Common.CurrentVersion.targets @@ -3810,7 +3810,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. contribute to incremental build inconsistencies. ============================================================ --> - + @@ -3819,6 +3819,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. + Date: Mon, 4 Nov 2024 17:48:35 +0800 Subject: [PATCH 2/8] Add test --- .../ProjectCache/ProjectCacheTests.cs | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs b/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs index 022ed16ed2c..3cec88bca50 100644 --- a/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs +++ b/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs @@ -10,6 +10,7 @@ using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; +using Microsoft.Build.CommandLine; using Microsoft.Build.Construction; using Microsoft.Build.Execution; using Microsoft.Build.Experimental.ProjectCache; @@ -18,10 +19,12 @@ using Microsoft.Build.Shared; using Microsoft.Build.Unittest; using Microsoft.Build.UnitTests; +using Microsoft.Build.UnitTests.Shared; using Microsoft.Build.Utilities; using Shouldly; using Xunit; using Xunit.Abstractions; +using Xunit.Sdk; using Task = System.Threading.Tasks.Task; namespace Microsoft.Build.Engine.UnitTests.ProjectCache @@ -1656,5 +1659,64 @@ private void SetEnvironmentForErrorLocations(ErrorLocations errorLocations, Erro } } } + + [Fact] + public void EmbeddedResourcesFileCompileCache() + { + var directory = _env.CreateFolder(); + string content = ObjectModelHelpers.CleanupFileContents( + """ + + + net8.0 + Exe + bin/ + + + + + + """); + var projectPath = directory.CreateFile("app.csproj", content).Path; + directory.CreateFile("Program.cs", + """ + using System; + using System.IO; + using System.Reflection; + + class Program + { + static void Main() + { + var assembly = Assembly.GetExecutingAssembly(); + var resourceNames = assembly.GetManifestResourceNames(); + + foreach (var resourceName in resourceNames) + { + using (var stream = assembly.GetManifestResourceStream(resourceName)) + using (var reader = new StreamReader(stream)) + { + var content = reader.ReadToEnd(); + Console.WriteLine($"Content of {resourceName}:"); + Console.WriteLine(content); + } + } + } + } + """); + var file1 = directory.CreateFile("File1.txt", "A=1"); + var file2 = directory.CreateFile("File2.txt", "B=1"); + RunnerUtilities.ExecBootstrapedMSBuild($"{projectPath} -restore", out bool success); + success.ShouldBeTrue(); + string output = RunnerUtilities.RunProcessAndGetOutput(Path.Combine(directory.Path, "bin/net8.0/app"), "", out success, false, _output); + output.ShouldContain("A=1"); + output.ShouldContain("B=1"); + FileUtilities.DeleteNoThrow(file1.Path); + RunnerUtilities.ExecBootstrapedMSBuild($"{projectPath}", out success); + success.ShouldBeTrue(); + output = RunnerUtilities.RunProcessAndGetOutput(Path.Combine(directory.Path, "bin/net8.0/app"), "", out success, false, _output); + output.ShouldNotContain("A=1"); + output.ShouldContain("B=1"); + } } } From 157544bc3ce605f32b2e2b383afb69d699c16b12 Mon Sep 17 00:00:00 2001 From: Jenny Bai Date: Mon, 4 Nov 2024 17:55:52 +0800 Subject: [PATCH 3/8] Add comment for test --- src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs b/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs index 3cec88bca50..1407897014f 100644 --- a/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs +++ b/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs @@ -1704,13 +1704,19 @@ static void Main() } } """); + + // Create EmbeddedResources file var file1 = directory.CreateFile("File1.txt", "A=1"); var file2 = directory.CreateFile("File2.txt", "B=1"); + + // Build and run the project RunnerUtilities.ExecBootstrapedMSBuild($"{projectPath} -restore", out bool success); success.ShouldBeTrue(); string output = RunnerUtilities.RunProcessAndGetOutput(Path.Combine(directory.Path, "bin/net8.0/app"), "", out success, false, _output); output.ShouldContain("A=1"); output.ShouldContain("B=1"); + + // Delete a file and build FileUtilities.DeleteNoThrow(file1.Path); RunnerUtilities.ExecBootstrapedMSBuild($"{projectPath}", out success); success.ShouldBeTrue(); From 4d2828c12b0480462431ca2766d4a5c94b22cd4b Mon Sep 17 00:00:00 2001 From: Jenny Bai Date: Fri, 8 Nov 2024 15:35:57 +0800 Subject: [PATCH 4/8] Add test comment --- .../ProjectCache/ProjectCacheTests.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs b/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs index 1407897014f..7e5e12b3e9f 100644 --- a/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs +++ b/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs @@ -1661,6 +1661,9 @@ private void SetEnvironmentForErrorLocations(ErrorLocations errorLocations, Erro } [Fact] + /// + /// https://github.com/dotnet/msbuild/issues/5334 + /// public void EmbeddedResourcesFileCompileCache() { var directory = _env.CreateFolder(); @@ -1710,16 +1713,16 @@ static void Main() var file2 = directory.CreateFile("File2.txt", "B=1"); // Build and run the project - RunnerUtilities.ExecBootstrapedMSBuild($"{projectPath} -restore", out bool success); - success.ShouldBeTrue(); - string output = RunnerUtilities.RunProcessAndGetOutput(Path.Combine(directory.Path, "bin/net8.0/app"), "", out success, false, _output); + string output = RunnerUtilities.ExecBootstrapedMSBuild($"{projectPath} -restore", out bool success); + success.ShouldBeTrue(output); + output = RunnerUtilities.RunProcessAndGetOutput(Path.Combine(directory.Path, "bin/net8.0/app"), "", out success, false, _output); output.ShouldContain("A=1"); output.ShouldContain("B=1"); // Delete a file and build FileUtilities.DeleteNoThrow(file1.Path); - RunnerUtilities.ExecBootstrapedMSBuild($"{projectPath}", out success); - success.ShouldBeTrue(); + output = RunnerUtilities.ExecBootstrapedMSBuild($"{projectPath}", out success); + success.ShouldBeTrue(output); output = RunnerUtilities.RunProcessAndGetOutput(Path.Combine(directory.Path, "bin/net8.0/app"), "", out success, false, _output); output.ShouldNotContain("A=1"); output.ShouldContain("B=1"); From e2a6554a67dc76732b217a74f0b7d3b6c906c675 Mon Sep 17 00:00:00 2001 From: Jenny Bai Date: Mon, 2 Dec 2024 19:05:51 +0800 Subject: [PATCH 5/8] Update the test case from sdk to .Net Framework --- .../ProjectCache/ProjectCacheTests.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs b/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs index 7e5e12b3e9f..d1b74ce9b66 100644 --- a/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs +++ b/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs @@ -1668,16 +1668,18 @@ public void EmbeddedResourcesFileCompileCache() { var directory = _env.CreateFolder(); string content = ObjectModelHelpers.CleanupFileContents( - """ - + $""" + - net8.0 + {MSBuildConstants.StandardTestTargetFrameworkVersion} Exe bin/ + + """); var projectPath = directory.CreateFile("app.csproj", content).Path; @@ -1687,7 +1689,7 @@ public void EmbeddedResourcesFileCompileCache() using System.IO; using System.Reflection; - class Program + class Programe { static void Main() { @@ -1715,7 +1717,7 @@ static void Main() // Build and run the project string output = RunnerUtilities.ExecBootstrapedMSBuild($"{projectPath} -restore", out bool success); success.ShouldBeTrue(output); - output = RunnerUtilities.RunProcessAndGetOutput(Path.Combine(directory.Path, "bin/net8.0/app"), "", out success, false, _output); + output = RunnerUtilities.RunProcessAndGetOutput(Path.Combine(directory.Path, "bin/app"), "", out success, false, _output); output.ShouldContain("A=1"); output.ShouldContain("B=1"); @@ -1723,7 +1725,7 @@ static void Main() FileUtilities.DeleteNoThrow(file1.Path); output = RunnerUtilities.ExecBootstrapedMSBuild($"{projectPath}", out success); success.ShouldBeTrue(output); - output = RunnerUtilities.RunProcessAndGetOutput(Path.Combine(directory.Path, "bin/net8.0/app"), "", out success, false, _output); + output = RunnerUtilities.RunProcessAndGetOutput(Path.Combine(directory.Path, "bin/app"), "", out success, false, _output); output.ShouldNotContain("A=1"); output.ShouldContain("B=1"); } From e1853f7962204593aa18533f66fc5ada1bc884b7 Mon Sep 17 00:00:00 2001 From: Jenny Bai Date: Tue, 3 Dec 2024 11:25:52 +0800 Subject: [PATCH 6/8] Revert "Update the test case from sdk to .Net Framework" This reverts commit e2a6554a67dc76732b217a74f0b7d3b6c906c675. --- .../ProjectCache/ProjectCacheTests.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs b/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs index d1b74ce9b66..7e5e12b3e9f 100644 --- a/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs +++ b/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs @@ -1668,18 +1668,16 @@ public void EmbeddedResourcesFileCompileCache() { var directory = _env.CreateFolder(); string content = ObjectModelHelpers.CleanupFileContents( - $""" - + """ + - {MSBuildConstants.StandardTestTargetFrameworkVersion} + net8.0 Exe bin/ - - """); var projectPath = directory.CreateFile("app.csproj", content).Path; @@ -1689,7 +1687,7 @@ public void EmbeddedResourcesFileCompileCache() using System.IO; using System.Reflection; - class Programe + class Program { static void Main() { @@ -1717,7 +1715,7 @@ static void Main() // Build and run the project string output = RunnerUtilities.ExecBootstrapedMSBuild($"{projectPath} -restore", out bool success); success.ShouldBeTrue(output); - output = RunnerUtilities.RunProcessAndGetOutput(Path.Combine(directory.Path, "bin/app"), "", out success, false, _output); + output = RunnerUtilities.RunProcessAndGetOutput(Path.Combine(directory.Path, "bin/net8.0/app"), "", out success, false, _output); output.ShouldContain("A=1"); output.ShouldContain("B=1"); @@ -1725,7 +1723,7 @@ static void Main() FileUtilities.DeleteNoThrow(file1.Path); output = RunnerUtilities.ExecBootstrapedMSBuild($"{projectPath}", out success); success.ShouldBeTrue(output); - output = RunnerUtilities.RunProcessAndGetOutput(Path.Combine(directory.Path, "bin/app"), "", out success, false, _output); + output = RunnerUtilities.RunProcessAndGetOutput(Path.Combine(directory.Path, "bin/net8.0/app"), "", out success, false, _output); output.ShouldNotContain("A=1"); output.ShouldContain("B=1"); } From 42a85c4e0509489c93f9f0967d968936702617ef Mon Sep 17 00:00:00 2001 From: Jenny Bai Date: Mon, 6 Jan 2025 15:57:39 +0800 Subject: [PATCH 7/8] Skip the netfx unit since he netfx bootstrap layout created with 'dotnet build' is incomplete --- src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs b/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs index 7e5e12b3e9f..449bdf1401d 100644 --- a/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs +++ b/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs @@ -1660,7 +1660,7 @@ private void SetEnvironmentForErrorLocations(ErrorLocations errorLocations, Erro } } - [Fact] + [DotNetOnlyFact("The netfx bootstrap layout created with 'dotnet build' is incomplete")] /// /// https://github.com/dotnet/msbuild/issues/5334 /// From 08a7bf330af6b4a7b958c4a7c699f8e7566540fa Mon Sep 17 00:00:00 2001 From: Jenny Bai Date: Tue, 14 Jan 2025 15:58:53 +0800 Subject: [PATCH 8/8] Test --- src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs b/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs index 449bdf1401d..7e5e12b3e9f 100644 --- a/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs +++ b/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs @@ -1660,7 +1660,7 @@ private void SetEnvironmentForErrorLocations(ErrorLocations errorLocations, Erro } } - [DotNetOnlyFact("The netfx bootstrap layout created with 'dotnet build' is incomplete")] + [Fact] /// /// https://github.com/dotnet/msbuild/issues/5334 ///