diff --git a/MSBuild.sln b/MSBuild.sln
index caac39c6344..d5f7f3e7622 100644
--- a/MSBuild.sln
+++ b/MSBuild.sln
@@ -78,6 +78,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Build.BuildCheck.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Build.Templates", "template_feed\Microsoft.Build.Templates.csproj", "{A86EE74A-AEF0-42ED-A5A7-7A54BC0773D8}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Build.CommandLine.EndToEnd.Tests", "src\MSBuild.EndToEnd.Tests\Microsoft.Build.CommandLine.EndToEnd.Tests.csproj", "{29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -862,6 +864,30 @@ Global
{A86EE74A-AEF0-42ED-A5A7-7A54BC0773D8}.Release|x64.Build.0 = Release|Any CPU
{A86EE74A-AEF0-42ED-A5A7-7A54BC0773D8}.Release|x86.ActiveCfg = Release|Any CPU
{A86EE74A-AEF0-42ED-A5A7-7A54BC0773D8}.Release|x86.Build.0 = Release|Any CPU
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.Debug|ARM64.ActiveCfg = Debug|arm64
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.Debug|ARM64.Build.0 = Debug|arm64
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.Debug|x64.ActiveCfg = Debug|x64
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.Debug|x64.Build.0 = Debug|x64
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.Debug|x86.Build.0 = Debug|Any CPU
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.MachineIndependent|Any CPU.ActiveCfg = MachineIndependent|Any CPU
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.MachineIndependent|Any CPU.Build.0 = MachineIndependent|Any CPU
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.MachineIndependent|ARM64.ActiveCfg = MachineIndependent|arm64
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.MachineIndependent|ARM64.Build.0 = MachineIndependent|arm64
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.MachineIndependent|x64.ActiveCfg = MachineIndependent|x64
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.MachineIndependent|x64.Build.0 = MachineIndependent|x64
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.MachineIndependent|x86.ActiveCfg = MachineIndependent|Any CPU
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.MachineIndependent|x86.Build.0 = MachineIndependent|Any CPU
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.Release|ARM64.ActiveCfg = Release|arm64
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.Release|ARM64.Build.0 = Release|arm64
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.Release|x64.ActiveCfg = Release|x64
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.Release|x64.Build.0 = Release|x64
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.Release|x86.ActiveCfg = Release|Any CPU
+ {29F9B7E2-F4BE-1C61-B8B5-427BA6463E8F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/src/BuildCheck.UnitTests/EndToEndTests.cs b/src/BuildCheck.UnitTests/EndToEndTests.cs
index d251e8f5ecc..27fdadbd20d 100644
--- a/src/BuildCheck.UnitTests/EndToEndTests.cs
+++ b/src/BuildCheck.UnitTests/EndToEndTests.cs
@@ -162,7 +162,7 @@ private EmbedResourceTestOutput RunEmbeddedResourceTest(string resourceXmlToAdd,
const string templateToReplace = "###EmbeddedResourceToAdd";
TransientTestFolder workFolder = _env.CreateFolder(createFolder: true);
- CopyFilesRecursively(Path.Combine(TestAssetsRootPath, testAssetsFolderName), workFolder.Path);
+ FileSystemUtilities.CopyFilesRecursively(Path.Combine(TestAssetsRootPath, testAssetsFolderName), workFolder.Path);
ReplaceStringInFile(Path.Combine(workFolder.Path, referencedProjectName, $"{referencedProjectName}.csproj"),
templateToReplace, resourceXmlToAdd);
File.Copy(
@@ -198,21 +198,6 @@ void ReplaceStringInFile(string filePath, string original, string replacement)
}
}
- private static void CopyFilesRecursively(string sourcePath, string targetPath)
- {
- // First Create all directories
- foreach (string dirPath in Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories))
- {
- Directory.CreateDirectory(dirPath.Replace(sourcePath, targetPath));
- }
-
- // Then copy all the files & Replaces any files with the same name
- foreach (string newPath in Directory.GetFiles(sourcePath, "*", SearchOption.AllDirectories))
- {
- File.Copy(newPath, newPath.Replace(sourcePath, targetPath), true);
- }
- }
-
private static int GetWarningsCount(string output)
{
Regex regex = new Regex(@"(\d+) Warning\(s\)");
@@ -272,7 +257,7 @@ public void CopyToOutputTest(bool skipUnchangedDuringCopy)
const string entryProjectName = "EntryProject";
TransientTestFolder workFolder = _env.CreateFolder(createFolder: true);
- CopyFilesRecursively(Path.Combine(TestAssetsRootPath, testAssetsFolderName), workFolder.Path);
+ FileSystemUtilities.CopyFilesRecursively(Path.Combine(TestAssetsRootPath, testAssetsFolderName), workFolder.Path);
_env.SetCurrentDirectory(Path.Combine(workFolder.Path, entryProjectName));
@@ -377,7 +362,7 @@ public void TFMConfusionCheckTest(string tfmString, string cliSuffix, bool shoul
const string templateToReplace = "###TFM";
TransientTestFolder workFolder = _env.CreateFolder(createFolder: true);
- CopyFilesRecursively(Path.Combine(TestAssetsRootPath, testAssetsFolderName), workFolder.Path);
+ FileSystemUtilities.CopyFilesRecursively(Path.Combine(TestAssetsRootPath, testAssetsFolderName), workFolder.Path);
ReplaceStringInFile(Path.Combine(workFolder.Path, $"{projectName}.csproj"),
templateToReplace, tfmString);
diff --git a/src/MSBuild.EndToEnd.Tests/Microsoft.Build.CommandLine.EndToEnd.Tests.csproj b/src/MSBuild.EndToEnd.Tests/Microsoft.Build.CommandLine.EndToEnd.Tests.csproj
new file mode 100644
index 00000000000..655efccecab
--- /dev/null
+++ b/src/MSBuild.EndToEnd.Tests/Microsoft.Build.CommandLine.EndToEnd.Tests.csproj
@@ -0,0 +1,31 @@
+
+
+
+ $(RuntimeOutputTargetFrameworks)
+ $(RuntimeOutputPlatformTarget)
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/MSBuild.EndToEnd.Tests/MultithreadedExecution_Tests.cs b/src/MSBuild.EndToEnd.Tests/MultithreadedExecution_Tests.cs
new file mode 100644
index 00000000000..b5db3e9ce51
--- /dev/null
+++ b/src/MSBuild.EndToEnd.Tests/MultithreadedExecution_Tests.cs
@@ -0,0 +1,149 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.IO;
+using System.Linq;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Logging;
+using Microsoft.Build.Shared;
+using Microsoft.Build.UnitTests;
+using Microsoft.Build.UnitTests.Shared;
+using Shouldly;
+using Xunit;
+using Xunit.Abstractions;
+
+#nullable disable
+
+namespace Microsoft.Build.EndToEndTests
+{
+ ///
+ /// Tests for multithreaded MSBuild execution scenarios using test assets.
+ ///
+ public class MultithreadedExecution_Tests : IClassFixture, IDisposable
+ {
+ private readonly ITestOutputHelper _output;
+ private readonly TestEnvironment _env;
+ private readonly string _testAssetDir;
+
+ private readonly int _timeoutInMilliseconds = 60_000;
+
+ // Common parameters for all multithreaded tests:
+ // /nodereuse:false - Prevents MSBuild server processes from persisting between tests,
+ // ensuring proper test isolation and avoiding potential timeouts
+ // /v:minimal - Reduces log verbosity for cleaner test output and better performance
+ private const string CommonMSBuildArgs = "/nodereuse:false /v:minimal";
+
+ public MultithreadedExecution_Tests(ITestOutputHelper output, TestSolutionAssetsFixture testAssetFixture)
+ {
+ _output = output;
+ _env = TestEnvironment.Create(output);
+ _testAssetDir = testAssetFixture.TestAssetDir;
+ }
+
+ public void Dispose()
+ {
+ _env.Dispose();
+ }
+
+ ///
+ /// Prepares an isolated copy of test assets in a temporary directory for each test run.
+ /// This ensures fresh builds and proper test isolation.
+ ///
+ /// Test asset
+ /// TestSolutionAsset for the copied asset in a temporary folder.
+ private TestSolutionAsset PrepareIsolatedTestAssets(TestSolutionAsset testAsset)
+ {
+ string sourceAssetDir = Path.Combine(_testAssetDir, testAsset.SolutionFolder);
+
+ // Ensure source test asset exists
+ Directory.Exists(sourceAssetDir).ShouldBeTrue($"Test asset not found: {sourceAssetDir}.");
+
+ // Create isolated copy of entire test asset directory structure
+ TransientTestFolder workFolder = _env.CreateFolder(createFolder: true);
+
+ FileSystemUtilities.CopyFilesRecursively(sourceAssetDir, workFolder.Path);
+
+ // Return TestSolutionAsset with temp folder and project file
+ return new TestSolutionAsset(workFolder.Path, testAsset.ProjectRelativePath);
+ }
+
+ ///
+ /// Helper method to resolve TestSolutionAsset instances by name.
+ /// This is the easiest way to work around the limitation that [InlineData] cannot pass complex objects like TestSolutionAsset directly.
+ ///
+ private static TestSolutionAsset GetTestAssetByName(string testAssetName)
+ {
+ return testAssetName switch
+ {
+ nameof(TestSolutionAssetsFixture.SingleProject) => TestSolutionAssetsFixture.SingleProject,
+ nameof(TestSolutionAssetsFixture.ProjectWithDependencies) => TestSolutionAssetsFixture.ProjectWithDependencies,
+ _ => throw new ArgumentException($"Unknown test asset name: {testAssetName}", nameof(testAssetName))
+ };
+ }
+
+ ///
+ /// Tests building projects with various multithreading flags.
+ ///
+ [Theory]
+ [InlineData(nameof(TestSolutionAssetsFixture.SingleProject), "/m:1 /mt")]
+ [InlineData(nameof(TestSolutionAssetsFixture.SingleProject), "/m:8 /mt")]
+ [InlineData(nameof(TestSolutionAssetsFixture.ProjectWithDependencies), "/m:1 /mt")]
+ [InlineData(nameof(TestSolutionAssetsFixture.ProjectWithDependencies), "/m:2 /mt")]
+ [InlineData(nameof(TestSolutionAssetsFixture.ProjectWithDependencies), "/m:8 /mt")]
+ public void MultithreadedBuild_Success(string testAssetName, string multithreadingArgs)
+ {
+ // Resolve TestSolutionAsset from name
+ TestSolutionAsset testAsset = GetTestAssetByName(testAssetName);
+
+ // Prepare isolated copy of test assets to ensure fresh builds
+ TestSolutionAsset isolatedAsset = PrepareIsolatedTestAssets(testAsset);
+
+ string output = RunnerUtilities.ExecBootstrapedMSBuild(
+ $"\"{isolatedAsset.ProjectPath}\" {multithreadingArgs} {CommonMSBuildArgs}",
+ out bool success,
+ timeoutMilliseconds: _timeoutInMilliseconds);
+
+ success.ShouldBeTrue($"Build failed with args '{multithreadingArgs}' for {testAsset.SolutionFolder}. Output:\\n{output}");
+
+ _output.WriteLine($"Built {testAsset.SolutionFolder} with arguments {multithreadingArgs}.");
+ }
+
+ ///
+ /// Tests binary logging with multithreaded builds and verifies replay functionality.
+ ///
+ [Theory]
+ [InlineData(nameof(TestSolutionAssetsFixture.SingleProject), "/m:8 /mt")]
+ public void MultithreadedBuild_BinaryLogging(string testAssetName, string multithreadingArgs)
+ {
+ // Resolve TestSolutionAsset from name
+ TestSolutionAsset testAsset = GetTestAssetByName(testAssetName);
+
+ // Prepare isolated copy of test assets to ensure fresh builds
+ TestSolutionAsset isolatedAsset = PrepareIsolatedTestAssets(testAsset);
+
+ string binlogPath = Path.Combine(isolatedAsset.SolutionFolder, "build.binlog");
+
+ // Build with binary logging
+ string output = RunnerUtilities.ExecBootstrapedMSBuild(
+ $"\"{isolatedAsset.ProjectPath}\" {multithreadingArgs} /bl:\"{binlogPath}\" {CommonMSBuildArgs}",
+ out bool success,
+ timeoutMilliseconds: _timeoutInMilliseconds);
+
+ success.ShouldBeTrue($"Build failed with args '{multithreadingArgs}' for {testAsset.SolutionFolder}. Output:\\n{output}.");
+
+ // Verify binary log was created and has content
+ File.Exists(binlogPath).ShouldBeTrue("Binary log file was not created.");
+
+ // Test binlog replay
+ string replayOutput = RunnerUtilities.ExecBootstrapedMSBuild(
+ $"\"{binlogPath}\" {CommonMSBuildArgs}",
+ out bool replaySuccess,
+ timeoutMilliseconds: _timeoutInMilliseconds);
+
+ replaySuccess.ShouldBeTrue($"Binlog replay failed. Output:\\n{replayOutput}");
+
+ _output.WriteLine($"Built and replayed {testAsset.SolutionFolder} with arguments {multithreadingArgs}.");
+ }
+ }
+}
diff --git a/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/ConsoleApp/ConsoleApp.csproj b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/ConsoleApp/ConsoleApp.csproj
new file mode 100644
index 00000000000..e9c22e44cdd
--- /dev/null
+++ b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/ConsoleApp/ConsoleApp.csproj
@@ -0,0 +1,11 @@
+
+
+ Exe
+ net10.0
+ latest
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/ConsoleApp/Program.cs b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/ConsoleApp/Program.cs
new file mode 100644
index 00000000000..26d73d8bcaf
--- /dev/null
+++ b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/ConsoleApp/Program.cs
@@ -0,0 +1,9 @@
+namespace ConsoleApp
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ }
+ }
+}
diff --git a/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library1/Class1.cs b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library1/Class1.cs
new file mode 100644
index 00000000000..c8224d76a9a
--- /dev/null
+++ b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library1/Class1.cs
@@ -0,0 +1,7 @@
+namespace Library1
+{
+ public class Class1
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library1/Library1.csproj b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library1/Library1.csproj
new file mode 100644
index 00000000000..77cb2792044
--- /dev/null
+++ b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library1/Library1.csproj
@@ -0,0 +1,11 @@
+
+
+ net10.0
+ latest
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library2/Class2.cs b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library2/Class2.cs
new file mode 100644
index 00000000000..7de56b98ddb
--- /dev/null
+++ b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library2/Class2.cs
@@ -0,0 +1,7 @@
+namespace Library2
+{
+ public class Class2
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library2/Library2.csproj b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library2/Library2.csproj
new file mode 100644
index 00000000000..77cb2792044
--- /dev/null
+++ b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library2/Library2.csproj
@@ -0,0 +1,11 @@
+
+
+ net10.0
+ latest
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library3/Class3.cs b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library3/Class3.cs
new file mode 100644
index 00000000000..50a703c482b
--- /dev/null
+++ b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library3/Class3.cs
@@ -0,0 +1,7 @@
+namespace Library3
+{
+ public class Class3
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library3/Library3.csproj b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library3/Library3.csproj
new file mode 100644
index 00000000000..53502388eb3
--- /dev/null
+++ b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library3/Library3.csproj
@@ -0,0 +1,6 @@
+
+
+ net10.0
+ latest
+
+
\ No newline at end of file
diff --git a/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library4/Class4.cs b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library4/Class4.cs
new file mode 100644
index 00000000000..50a703c482b
--- /dev/null
+++ b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library4/Class4.cs
@@ -0,0 +1,7 @@
+namespace Library3
+{
+ public class Class3
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library4/Library4.csproj b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library4/Library4.csproj
new file mode 100644
index 00000000000..53502388eb3
--- /dev/null
+++ b/src/MSBuild.EndToEnd.Tests/TestAssets/ProjectWithDependencies/Library4/Library4.csproj
@@ -0,0 +1,6 @@
+
+
+ net10.0
+ latest
+
+
\ No newline at end of file
diff --git a/src/MSBuild.EndToEnd.Tests/TestAssets/SingleProject/Program.cs b/src/MSBuild.EndToEnd.Tests/TestAssets/SingleProject/Program.cs
new file mode 100644
index 00000000000..6d3de979e33
--- /dev/null
+++ b/src/MSBuild.EndToEnd.Tests/TestAssets/SingleProject/Program.cs
@@ -0,0 +1,12 @@
+using System;
+
+namespace ConsoleApp
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/MSBuild.EndToEnd.Tests/TestAssets/SingleProject/SingleProject.csproj b/src/MSBuild.EndToEnd.Tests/TestAssets/SingleProject/SingleProject.csproj
new file mode 100644
index 00000000000..5c0a78df5ac
--- /dev/null
+++ b/src/MSBuild.EndToEnd.Tests/TestAssets/SingleProject/SingleProject.csproj
@@ -0,0 +1,10 @@
+
+
+
+ Exe
+ net10.0
+ enable
+ enable
+
+
+
\ No newline at end of file
diff --git a/src/MSBuild.EndToEnd.Tests/TestAssetsFixture.cs b/src/MSBuild.EndToEnd.Tests/TestAssetsFixture.cs
new file mode 100644
index 00000000000..30099928f72
--- /dev/null
+++ b/src/MSBuild.EndToEnd.Tests/TestAssetsFixture.cs
@@ -0,0 +1,54 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.IO;
+using Microsoft.Build.UnitTests.Shared;
+using Shouldly;
+
+#nullable disable
+
+namespace Microsoft.Build.EndToEndTests
+{
+ ///
+ /// Fixture for test solution assets that handles expensive initialization like NuGet restore.
+ ///
+ public class TestSolutionAssetsFixture : IDisposable
+ {
+ public string TestAssetDir { get; }
+
+ // Test solution asset definitions
+ public static readonly TestSolutionAsset SingleProject = new("SingleProject", "SingleProject.csproj");
+ public static readonly TestSolutionAsset ProjectWithDependencies = new("ProjectWithDependencies", "ConsoleApp/ConsoleApp.csproj");
+
+ private static readonly TestSolutionAsset[] AssetsToRestore =
+ [
+ SingleProject,
+ ProjectWithDependencies
+ ];
+
+ public TestSolutionAssetsFixture()
+ {
+ TestAssetDir = Path.Combine(Path.GetDirectoryName(typeof(TestSolutionAssetsFixture).Assembly.Location) ?? AppContext.BaseDirectory, "TestAssets");
+ RestoreTestAssets();
+ }
+
+ private void RestoreTestAssets()
+ {
+ foreach (var asset in AssetsToRestore)
+ {
+ string projectPath = Path.Combine(TestAssetDir, asset.ProjectPath);
+
+ File.Exists(projectPath).ShouldBeTrue($"Test asset project not found: {projectPath}");
+
+ string output = RunnerUtilities.ExecBootstrapedMSBuild($"\"{projectPath}\" /t:Restore /v:minimal", out bool success);
+ success.ShouldBeTrue($"Failed to restore test asset {asset.SolutionFolder}\\{asset.ProjectRelativePath}. Output:\n{output}");
+ }
+ }
+
+ public void Dispose()
+ {
+ // Clean up if needed
+ }
+ }
+}
diff --git a/src/MSBuild.EndToEnd.Tests/TestSolutionAsset.cs b/src/MSBuild.EndToEnd.Tests/TestSolutionAsset.cs
new file mode 100644
index 00000000000..03abe9fce67
--- /dev/null
+++ b/src/MSBuild.EndToEnd.Tests/TestSolutionAsset.cs
@@ -0,0 +1,32 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.IO;
+
+#nullable disable
+
+namespace Microsoft.Build.EndToEndTests
+{
+ ///
+ /// Represents a test solution asset.
+ ///
+ public readonly struct TestSolutionAsset
+ {
+ // Solution folder containing the test asset
+ public string SolutionFolder { get; }
+
+ // Path to main (entry) project file relative to the solution folder
+ public string ProjectRelativePath { get; }
+
+ public TestSolutionAsset(string solutionFolder, string projectFile)
+ {
+ SolutionFolder = solutionFolder;
+ ProjectRelativePath = projectFile;
+ }
+
+ ///
+ /// Gets the full relative path from TestAssets root to the project file.
+ ///
+ public string ProjectPath => Path.Combine(SolutionFolder, ProjectRelativePath);
+ }
+}
\ No newline at end of file
diff --git a/src/MSBuild/AssemblyInfo.cs b/src/MSBuild/AssemblyInfo.cs
index f93e8a6db00..5cee7eb069e 100644
--- a/src/MSBuild/AssemblyInfo.cs
+++ b/src/MSBuild/AssemblyInfo.cs
@@ -8,6 +8,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+[assembly: InternalsVisibleTo("Microsoft.Build.CommandLine.EndToEnd.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010015c01ae1f50e8cc09ba9eac9147cf8fd9fce2cfe9f8dce4f7301c4132ca9fb50ce8cbf1df4dc18dd4d210e4345c744ecb3365ed327efdbc52603faa5e21daa11234c8c4a73e51f03bf192544581ebe107adee3a34928e39d04e524a9ce729d5090bfd7dad9d10c722c0def9ccc08ff0a03790e48bcd1f9b6c476063e1966a1c4")]
[assembly: InternalsVisibleTo("Microsoft.Build.CommandLine.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010015c01ae1f50e8cc09ba9eac9147cf8fd9fce2cfe9f8dce4f7301c4132ca9fb50ce8cbf1df4dc18dd4d210e4345c744ecb3365ed327efdbc52603faa5e21daa11234c8c4a73e51f03bf192544581ebe107adee3a34928e39d04e524a9ce729d5090bfd7dad9d10c722c0def9ccc08ff0a03790e48bcd1f9b6c476063e1966a1c4")]
[assembly: InternalsVisibleTo("Microsoft.Build.Utilities.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010015c01ae1f50e8cc09ba9eac9147cf8fd9fce2cfe9f8dce4f7301c4132ca9fb50ce8cbf1df4dc18dd4d210e4345c744ecb3365ed327efdbc52603faa5e21daa11234c8c4a73e51f03bf192544581ebe107adee3a34928e39d04e524a9ce729d5090bfd7dad9d10c722c0def9ccc08ff0a03790e48bcd1f9b6c476063e1966a1c4")]
diff --git a/src/UnitTests.Shared/FileSystemUtilities.cs b/src/UnitTests.Shared/FileSystemUtilities.cs
new file mode 100644
index 00000000000..b66bd353b08
--- /dev/null
+++ b/src/UnitTests.Shared/FileSystemUtilities.cs
@@ -0,0 +1,35 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.IO;
+
+#nullable disable
+
+namespace Microsoft.Build.UnitTests.Shared
+{
+ ///
+ /// File system utilities for unit tests.
+ ///
+ public static class FileSystemUtilities
+ {
+ ///
+ /// Recursively copies all files and directories from source to target path.
+ ///
+ /// Source directory path
+ /// Target directory path
+ public static void CopyFilesRecursively(string sourcePath, string targetPath)
+ {
+ // First Create all directories
+ foreach (string dirPath in Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories))
+ {
+ Directory.CreateDirectory(dirPath.Replace(sourcePath, targetPath));
+ }
+
+ // Then copy all the files & Replaces any files with the same name
+ foreach (string newPath in Directory.GetFiles(sourcePath, "*", SearchOption.AllDirectories))
+ {
+ File.Copy(newPath, newPath.Replace(sourcePath, targetPath), true);
+ }
+ }
+ }
+}
\ No newline at end of file