Skip to content
Merged
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
10 changes: 5 additions & 5 deletions src/Build.UnitTests/NetTaskHost_E2E_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void NetTaskHostTest()

string testProjectPath = Path.Combine(TestAssetsRootPath, "ExampleNetTask", "TestNetTask", "TestNetTask.csproj");

string testTaskOutput = RunnerUtilities.ExecBootstrapedMSBuild($"{testProjectPath} -restore -v:n", out bool successTestTask);
string testTaskOutput = RunnerUtilities.ExecBootstrapedMSBuild($"{testProjectPath} -restore -v:n -p:LatestDotNetCoreForMSBuild={RunnerUtilities.LatestDotNetCoreForMSBuild}", out bool successTestTask);

if (!successTestTask)
{
Expand All @@ -63,7 +63,7 @@ public void NetTaskHost_CorrectPathsEscapingTest()
using TestEnvironment env = TestEnvironment.Create(_output);
var dotnetPath = env.GetEnvironmentVariable("DOTNET_ROOT");
string testProjectPath = Path.Combine(TestAssetsRootPath, "ExampleNetTask", "TestNetTask", "TestNetTask.csproj");
string testTaskOutput = RunnerUtilities.ExecBootstrapedMSBuild($"{testProjectPath} -restore -v:n", out bool successTestTask);
string testTaskOutput = RunnerUtilities.ExecBootstrapedMSBuild($"{testProjectPath} -restore -v:n -p:LatestDotNetCoreForMSBuild={RunnerUtilities.LatestDotNetCoreForMSBuild}", out bool successTestTask);

if (!successTestTask)
{
Expand Down Expand Up @@ -124,7 +124,7 @@ public void MSBuildTaskInNetHostTest()

string testProjectPath = Path.Combine(TestAssetsRootPath, "ExampleNetTask", "TestMSBuildTaskInNet", "TestMSBuildTaskInNet.csproj");

string testTaskOutput = RunnerUtilities.ExecBootstrapedMSBuild($"{testProjectPath} -restore -v:n", out bool successTestTask);
string testTaskOutput = RunnerUtilities.ExecBootstrapedMSBuild($"{testProjectPath} -restore -v:n -p:LatestDotNetCoreForMSBuild={RunnerUtilities.LatestDotNetCoreForMSBuild}", out bool successTestTask);

if (!successTestTask)
{
Expand All @@ -143,7 +143,7 @@ public void NetTaskWithImplicitHostParamsTest()

string testProjectPath = Path.Combine(TestAssetsRootPath, "ExampleNetTask", "TestNetTaskWithImplicitParams", "TestNetTaskWithImplicitParams.csproj");

string testTaskOutput = RunnerUtilities.ExecBootstrapedMSBuild($"{testProjectPath} -restore -v:n", out bool successTestTask);
string testTaskOutput = RunnerUtilities.ExecBootstrapedMSBuild($"{testProjectPath} -restore -v:n -p:LatestDotNetCoreForMSBuild={RunnerUtilities.LatestDotNetCoreForMSBuild}", out bool successTestTask);

if (!successTestTask)
{
Expand All @@ -164,4 +164,4 @@ public void NetTaskWithImplicitHostParamsTest()
testTaskOutput.ShouldContain("Found item: Banana");
}
}
}
}
2 changes: 1 addition & 1 deletion src/Build.UnitTests/TaskHostFactoryLifecycle_E2E_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private string ExecuteBuildWithTaskHost(string runtimeToUse, string taskFactoryT
string testProjectPath = Path.Combine(TestAssetsRootPath, "TaskHostLifecycleTestApp.csproj");

string output = RunnerUtilities.ExecBootstrapedMSBuild(
$"{testProjectPath} -v:n -restore /p:RuntimeToUse={runtimeToUse} /p:TaskFactoryToUse={taskFactoryToUse}",
$"{testProjectPath} -v:n -restore /p:RuntimeToUse={runtimeToUse} /p:TaskFactoryToUse={taskFactoryToUse} /p:LatestDotNetCoreForMSBuild={RunnerUtilities.LatestDotNetCoreForMSBuild}",
out bool success,
outputHelper: _output);

Expand Down
2 changes: 1 addition & 1 deletion src/Build.UnitTests/TerminalLogger_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ public async Task ProjectFinishedReportsTargetFrameworkAndRuntimeIdentifier()
{
// this project will report a TFM and a RID and so will show a both in the output
var buildOutputEvent = MakeBuildOutputEventArgs(_projectFile);
InvokeLoggerCallbacksForSimpleProject(succeeded: true, properties: [("TargetFramework", "net10.0"), ("RuntimeIdentifier", "win-x64")], additionalCallbacks: () =>
InvokeLoggerCallbacksForSimpleProject(succeeded: true, properties: [("TargetFramework", RunnerUtilities.LatestDotNetCoreForMSBuild), ("RuntimeIdentifier", "win-x64")], additionalCallbacks: () =>
{
_centralNodeEventSource.InvokeMessageRaised(buildOutputEvent);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<TargetFramework>$(LatestDotNetCoreForMSBuild)</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net10.0</TargetFrameworks>
<TargetFrameworks>$(LatestDotNetCoreForMSBuild)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<TargetFramework>$(LatestDotNetCoreForMSBuild)</TargetFramework>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<TargetFramework>$(LatestDotNetCoreForMSBuild)</TargetFramework>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<TargetFramework>$(LatestDotNetCoreForMSBuild)</TargetFramework>
<TestProjectFolder>$([System.IO.Path]::GetFullPath('$([System.IO.Path]::Combine('$(AssemblyLocation)', '..'))'))</TestProjectFolder>
<ExampleTaskPath>$([System.IO.Path]::Combine('$(TestProjectFolder)', '$(TargetFramework)', 'ExampleTask.dll'))</ExampleTaskPath>
</PropertyGroup>
Expand Down
131 changes: 71 additions & 60 deletions src/BuildCheck.UnitTests/EndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace Microsoft.Build.BuildCheck.UnitTests;
public class EndToEndTests : IDisposable
{
private const string EditorConfigFileName = ".editorconfig";
private const string LatestDotNetCoreForMSBuild = "net10.0";

private readonly TestEnvironment _env;

Expand Down Expand Up @@ -171,7 +170,7 @@ private EmbedResourceTestOutput RunEmbeddedResourceTest(string resourceXmlToAdd,

_env.SetCurrentDirectory(Path.Combine(workFolder.Path, entryProjectName));

string output = RunnerUtilities.ExecBootstrapedMSBuild("-check -restore /p:WarnOnCultureOverwritten=True /p:RespectCulture=" + (respectCulture ? "True" : "\"\""), out bool success, timeoutMilliseconds: timeoutInMilliseconds);
string output = RunnerUtilities.ExecBootstrapedMSBuild($"-check -restore /p:WarnOnCultureOverwritten=True /p:RespectCulture={(respectCulture ? "True" : "\"\"")} /p:LatestDotNetCoreForMSBuild={RunnerUtilities.LatestDotNetCoreForMSBuild}", out bool success, timeoutMilliseconds: timeoutInMilliseconds);
_env.Output.WriteLine(output);
_env.Output.WriteLine("=========================");
success.ShouldBeTrue();
Expand Down Expand Up @@ -232,7 +231,7 @@ private readonly record struct CopyTestOutput(

private CopyTestOutput RunCopyToOutputTest(bool restore, bool skipUnchangedDuringCopy)
{
string output = RunnerUtilities.ExecBootstrapedMSBuild($"-check {(restore ? "-restore" : null)} /p:SkipUnchanged={(skipUnchangedDuringCopy ? "True" : "\"\"")}", out bool success, timeoutMilliseconds: timeoutInMilliseconds);
string output = RunnerUtilities.ExecBootstrapedMSBuild($"-check {(restore ? "-restore" : null)} /p:SkipUnchanged={(skipUnchangedDuringCopy ? "True" : "\"\"")} /p:LatestDotNetCoreForMSBuild={RunnerUtilities.LatestDotNetCoreForMSBuild}", out bool success, timeoutMilliseconds: timeoutInMilliseconds);
_env.Output.WriteLine(output);
_env.Output.WriteLine("=========================");
success.ShouldBeTrue();
Expand Down Expand Up @@ -361,19 +360,26 @@ public void WarningsCountExceedsLimitTest(bool buildInOutOfProcessNode, bool lim
}
}

private const string testAssetsFolder = "TFMConfusionCheck";

public static IEnumerable<object[]> TFMConfusionCheckTestData()
{
yield return [$"""<TargetFramework>{RunnerUtilities.LatestDotNetCoreForMSBuild}</TargetFramework>""", "", false];
yield return [$"""<TargetFrameworks>{RunnerUtilities.LatestDotNetCoreForMSBuild};net472</TargetFrameworks>""", "", false];
yield return [$"""<TargetFrameworks>{RunnerUtilities.LatestDotNetCoreForMSBuild};net472</TargetFrameworks>""", $" /p:TargetFramework={RunnerUtilities.LatestDotNetCoreForMSBuild}", false];
yield return [$"""<TargetFramework></TargetFramework><TargetFrameworks>{RunnerUtilities.LatestDotNetCoreForMSBuild};net472</TargetFrameworks>""", "", false];
yield return [$"""<TargetFramework /><TargetFrameworks>{RunnerUtilities.LatestDotNetCoreForMSBuild};net472</TargetFrameworks>""", "", false];
yield return [$"""<TargetFramework>{RunnerUtilities.LatestDotNetCoreForMSBuild}</TargetFramework><TargetFrameworks></TargetFrameworks>""", "", false];
yield return [$"""<TargetFramework>{RunnerUtilities.LatestDotNetCoreForMSBuild}</TargetFramework><TargetFrameworks />""", "", false];
yield return [$"""<TargetFramework>{RunnerUtilities.LatestDotNetCoreForMSBuild}</TargetFramework><TargetFrameworks>{RunnerUtilities.LatestDotNetCoreForMSBuild};net472</TargetFrameworks>""", "", true];
}

[Theory]
[InlineData($"""<TargetFramework>{LatestDotNetCoreForMSBuild}</TargetFramework>""", "", false)]
[InlineData($"""<TargetFrameworks>{LatestDotNetCoreForMSBuild};net472</TargetFrameworks>""", "", false)]
[InlineData($"""<TargetFrameworks>{LatestDotNetCoreForMSBuild};net472</TargetFrameworks>""", $" /p:TargetFramework={LatestDotNetCoreForMSBuild}", false)]
[InlineData($"""<TargetFramework></TargetFramework><TargetFrameworks>{LatestDotNetCoreForMSBuild};net472</TargetFrameworks>""", "", false)]
[InlineData($"""<TargetFramework /><TargetFrameworks>{LatestDotNetCoreForMSBuild};net472</TargetFrameworks>""", "", false)]
[InlineData($"""<TargetFramework>{LatestDotNetCoreForMSBuild}</TargetFramework><TargetFrameworks></TargetFrameworks>""", "", false)]
[InlineData($"""<TargetFramework>{LatestDotNetCoreForMSBuild}</TargetFramework><TargetFrameworks />""", "", false)]
[InlineData($"""<TargetFramework>{LatestDotNetCoreForMSBuild}</TargetFramework><TargetFrameworks>{LatestDotNetCoreForMSBuild};net472</TargetFrameworks>""", "", true)]
[MemberData(nameof(TFMConfusionCheckTestData))]
public void TFMConfusionCheckTest(string tfmString, string cliSuffix, bool shouldTriggerCheck)
{
const string testAssetsFolderName = "TFMConfusionCheck";
const string projectName = testAssetsFolderName;
const string projectName = testAssetsFolder;
const string templateToReplace = "###TFM";
TransientTestFolder workFolder = _env.CreateFolder(createFolder: true);

Expand Down Expand Up @@ -407,56 +413,61 @@ void ReplaceStringInFile(string filePath, string original, string replacement)
}
}

public static IEnumerable<object[]> TFMinNonSdkCheckTestData()
{
yield return [
"""
<Project ToolsVersion="msbuilddefaulttoolsversion">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
</PropertyGroup>
<Target Name="Build">
<Message Text="Build done"/>
</Target>
</Project>
""",
false];
yield return [
$"""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>{RunnerUtilities.LatestDotNetCoreForMSBuild}</TargetFramework>
</PropertyGroup>
</Project>
""",
false];
yield return [
"""
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<OutputPath>bin\Debug\</OutputPath>
<NoWarn>CS2008</NoWarn>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
""",
false];
yield return [
"""
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<TargetFramework>v4.8</TargetFramework>
<OutputPath>bin\Debug\</OutputPath>
<NoWarn>CS2008</NoWarn>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
""",
true];
}

// Windows only - due to targeting NetFx
[WindowsOnlyTheory]
[InlineData(
"""
<Project ToolsVersion="msbuilddefaulttoolsversion">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
</PropertyGroup>
<Target Name="Build">
<Message Text="Build done"/>
</Target>
</Project>
""",
false)]
[InlineData(
$"""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>{LatestDotNetCoreForMSBuild}</TargetFramework>
</PropertyGroup>
</Project>
""",
false)]
[InlineData(
"""
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<OutputPath>bin\Debug\</OutputPath>
<NoWarn>CS2008</NoWarn>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
""",
false)]
[InlineData(
"""
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<TargetFramework>v4.8</TargetFramework>
<OutputPath>bin\Debug\</OutputPath>
<NoWarn>CS2008</NoWarn>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
""",
true)]
[MemberData(nameof(TFMinNonSdkCheckTestData))]
public void TFMinNonSdkCheckTest(string projectContent, bool expectCheckTrigger)
{
TransientTestFolder workFolder = _env.CreateFolder(createFolder: true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<TargetFramework>$(LatestDotNetCoreForMSBuild)</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<TargetFramework>$(LatestDotNetCoreForMSBuild)</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<TargetFramework>$(LatestDotNetCoreForMSBuild)</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableCustomCulture>true</EnableCustomCulture>
Expand Down
5 changes: 3 additions & 2 deletions src/Tasks.UnitTests/Copy_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

using Xunit;
using Xunit.Abstractions;
using Microsoft.Build.UnitTests.Shared;

#nullable disable

Expand Down Expand Up @@ -3174,15 +3175,15 @@ public void CopyToFileWithSameCaseInsensitiveNameAsExistingDirectoryOnUnix()
Directory.CreateDirectory(tempDir);

// Create a subdirectory structure to match the real scenario
string outputDir = Path.Combine(tempDir, "bin", "Debug", "net10.0");
string outputDir = Path.Combine(tempDir, "bin", "Debug", RunnerUtilities.LatestDotNetCoreForMSBuild);
Directory.CreateDirectory(outputDir);

// Create a directory named "cs" (lowercase) in the output directory
string lowercaseDir = Path.Combine(outputDir, "cs");
Directory.CreateDirectory(lowercaseDir);

// Create a few source files to copy (representing multiple files being copied to same dest dir)
string sourceDir = Path.Combine(tempDir, "CS", "obj", "Debug", "net10.0");
string sourceDir = Path.Combine(tempDir, "CS", "obj", "Debug", RunnerUtilities.LatestDotNetCoreForMSBuild);
Directory.CreateDirectory(sourceDir);

string sourceFile1 = Path.Combine(sourceDir, "apphost");
Expand Down
7 changes: 6 additions & 1 deletion src/UnitTests.Shared/BootstrapLocationAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Microsoft.Build.UnitTests.Shared;

[System.AttributeUsage(System.AttributeTargets.Assembly)]
internal sealed class BootstrapLocationAttribute(string bootstrapRoot, string bootstrapMsBuildBinaryLocation, string bootstrapSdkVersion) : System.Attribute
internal sealed class BootstrapLocationAttribute(string bootstrapRoot, string bootstrapMsBuildBinaryLocation, string bootstrapSdkVersion, string latestDotNetCoreForMSBuild) : System.Attribute
{
/// <summary>
/// Path to the root of the bootstrap MSBuild (in artifacts folder).
Expand All @@ -22,4 +22,9 @@ internal sealed class BootstrapLocationAttribute(string bootstrapRoot, string bo
/// Returns the version of the SDK used by the bootstrap MSBuild.
/// </summary>
public string BootstrapSdkVersion { get; } = bootstrapSdkVersion;

/// <summary>
/// The latest .NET target framework setup in MSBuild.
/// </summary>
public string LatestDotNetCoreForMSBuild { get; } = latestDotNetCoreForMSBuild;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<_Parameter1>$(ArtifactsBinDir)bootstrap</_Parameter1>
<_Parameter2>$(TestBootstrapBinaryDestination)</_Parameter2>
<_Parameter3>$(BootstrapSdkVersion)</_Parameter3>
<_Parameter4>$(LatestDotNetCoreForMSBuild)</_Parameter4>
</AssemblyAttribute>

<AssemblyAttribute Include="Microsoft.Build.UnitTests.Shared.ArtifactsLocationAttribute">
Expand Down
2 changes: 2 additions & 0 deletions src/UnitTests.Shared/RunnerUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public static class RunnerUtilities

public static string BootstrapRootPath => BootstrapLocationAttribute.BootstrapRoot;

public static string LatestDotNetCoreForMSBuild => BootstrapLocationAttribute.LatestDotNetCoreForMSBuild;

internal static BootstrapLocationAttribute BootstrapLocationAttribute = Assembly.GetExecutingAssembly().GetCustomAttribute<BootstrapLocationAttribute>()
?? throw new InvalidOperationException("This test assembly does not have the BootstrapLocationAttribute");

Expand Down
Loading