diff --git a/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs b/src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs
index 022ed16ed2c..7e5e12b3e9f 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,73 @@ private void SetEnvironmentForErrorLocations(ErrorLocations errorLocations, Erro
}
}
}
+
+ [Fact]
+ ///
+ /// https://github.com/dotnet/msbuild/issues/5334
+ ///
+ 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);
+ }
+ }
+ }
+ }
+ """);
+
+ // Create EmbeddedResources file
+ var file1 = directory.CreateFile("File1.txt", "A=1");
+ var file2 = directory.CreateFile("File2.txt", "B=1");
+
+ // 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.ShouldContain("A=1");
+ output.ShouldContain("B=1");
+
+ // Delete a file and build
+ 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.ShouldNotContain("A=1");
+ output.ShouldContain("B=1");
+ }
}
}
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.
+