Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ void CheckAndReplaceAttribute(XAttribute attribute)
.Elements(ns + "KnownAppHostPack").First().Attribute("AppHostPackVersion"));
CheckAndReplaceAttribute(itemGroup
.Elements(ns + "KnownCrossgen2Pack").First().Attribute("Crossgen2PackVersion"));
CheckAndReplaceAttribute(itemGroup
.Elements(ns + "KnownILCompilerPack").First().Attribute("ILCompilerPackVersion"));

// TODO: remove this once we're using an SDK that contains https://github.com/dotnet/installer/pull/10250
var crossgen2Rids = itemGroup.Elements(ns + "KnownCrossgen2Pack").First().Attribute("Crossgen2RuntimeIdentifiers");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public GivenThatWeWantToPublishAnAotApp(ITestOutputHelper log) : base(log)
}

[RequiresMSBuildVersionTheory("17.0.0.32901")]
[InlineData(ToolsetInfo.CurrentTargetFramework)]
[MemberData(nameof(Net7Plus), MemberType = typeof(PublishTestUtils))]
public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_enabled(string targetFramework)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
Expand All @@ -58,7 +58,8 @@ public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_enabled(string
.Should().Pass()
.And.NotHaveStdOutContaining("IL2026")
.And.NotHaveStdErrContaining("NETSDK1179")
.And.NotHaveStdErrContaining("warning");
.And.NotHaveStdErrContaining("warning")
.And.NotHaveStdOutContaining("warning");

var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName;
var sharedLibSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".dll" : ".so";
Expand All @@ -74,14 +75,17 @@ public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_enabled(string
File.Exists(publishedDebugFile).Should().BeTrue();
IsNativeImage(publishedExe).Should().BeTrue();

GetKnownILCompilerPackVersion(testAsset, targetFramework, out string expectedVersion);
CheckIlcVersions(testAsset, targetFramework, expectedVersion);

var command = new RunExeCommand(Log, publishedExe)
.Execute().Should().Pass()
.And.HaveStdOutContaining("Hello World");
}
}

[RequiresMSBuildVersionTheory("17.0.0.32901")]
[InlineData(ToolsetInfo.CurrentTargetFramework)]
[MemberData(nameof(Net7Plus), MemberType = typeof(PublishTestUtils))]
public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_false(string targetFramework)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Expand All @@ -99,7 +103,8 @@ public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_false(string t
.Should().Pass()
.And.NotHaveStdOutContaining("IL2026")
.And.NotHaveStdErrContaining("NETSDK1179")
.And.NotHaveStdErrContaining("warning");
.And.NotHaveStdErrContaining("warning")
.And.NotHaveStdOutContaining("warning");

var publishDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName;
var publishedDll = Path.Combine(publishDirectory, $"{projectName}.dll");
Expand Down Expand Up @@ -310,7 +315,7 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_enabled(string
.Execute().Should().Pass()
.And.HaveStdOutContaining("Hello World");

CheckIlcVersions(Path.Combine(testAsset.TestRoot, testProject.Name), targetFramework, ExplicitPackageVersion);
CheckIlcVersions(testAsset, targetFramework, ExplicitPackageVersion);
}
}

Expand Down Expand Up @@ -355,7 +360,7 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_empty(string t
}

[RequiresMSBuildVersionTheory("17.0.0.32901")]
[InlineData(ToolsetInfo.CurrentTargetFramework)]
[MemberData(nameof(Net7Plus), MemberType = typeof(PublishTestUtils))]
public void NativeAot_hw_runs_with_cross_target_PublishAot_is_enabled(string targetFramework)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && (RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.X64))
Expand All @@ -377,12 +382,15 @@ public void NativeAot_hw_runs_with_cross_target_PublishAot_is_enabled(string tar
var publishedExe = Path.Combine(publishDirectory, $"{testProject.Name}{Constants.ExeSuffix}");
File.Exists(publishedDll).Should().BeFalse();
File.Exists(publishedExe).Should().BeTrue();

GetKnownILCompilerPackVersion(testAsset, targetFramework, out string expectedVersion);
CheckIlcVersions(testAsset, targetFramework, expectedVersion);
}
}


[RequiresMSBuildVersionTheory("17.0.0.32901")]
[InlineData(ToolsetInfo.CurrentTargetFramework)]
[MemberData(nameof(Net7Plus), MemberType = typeof(PublishTestUtils))]
public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled(string targetFramework)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && (RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.X64))
Expand Down Expand Up @@ -413,7 +421,7 @@ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled(
File.Exists(publishedDll).Should().BeFalse();
File.Exists(publishedExe).Should().BeTrue();

CheckIlcVersions(Path.Combine(testAsset.TestRoot, testProject.Name), targetFramework, ExplicitPackageVersion);
CheckIlcVersions(testAsset, targetFramework, ExplicitPackageVersion);
}
}

Expand Down Expand Up @@ -545,7 +553,7 @@ public void Requires_analyzers_produce_warnings_without_PublishAot_being_set(str
}

[RequiresMSBuildVersionTheory("17.0.0.32901")]
[InlineData(ToolsetInfo.CurrentTargetFramework)]
[MemberData(nameof(Net7Plus), MemberType = typeof(PublishTestUtils))]
public void NativeAot_compiler_runs_when_PublishAot_is_enabled(string targetFramework)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
Expand Down Expand Up @@ -704,28 +712,41 @@ public void It_publishes_with_implicit_rid_with_NativeAotApp(string targetFramew
}
}

private void CheckIlcVersions(string projectPath, string targetFramework, string expectedVersion)
private void GetKnownILCompilerPackVersion(TestAsset testAsset, string targetFramework, out string version)
{
var getKnownPacks = new GetValuesCommand(testAsset, "KnownILCompilerPack", GetValuesCommand.ValueType.Item, targetFramework) {
MetadataNames = new List<string> { "TargetFramework", "ILCompilerPackVersion" }
};
getKnownPacks.Execute().Should().Pass();
var knownPacks = getKnownPacks.GetValuesWithMetadata();
version = knownPacks
.Where(i => i.metadata["TargetFramework"] == targetFramework)
.Select(i => i.metadata["ILCompilerPackVersion"])
.Single();
}

private void CheckIlcVersions(TestAsset testAsset, string targetFramework, string expectedVersion)
{
// Compiler version matches expected version
var ilcToolsPathCommand = new GetValuesCommand(Log, projectPath, targetFramework, "IlcToolsPath")
var ilcToolsPathCommand = new GetValuesCommand(testAsset, "IlcToolsPath", targetFramework: targetFramework)
{
DependsOnTargets = "WriteIlcRspFileForCompilation"
};
ilcToolsPathCommand.Execute().Should().Pass();
var ilcToolsPath = ilcToolsPathCommand.GetValues()[0];
var ilcVersion = Path.GetFileName(Path.GetDirectoryName(Path.GetDirectoryName(ilcToolsPath)));
ilcVersion.Should().Be(ExplicitPackageVersion);
ilcVersion.Should().Be(expectedVersion);

// Compilation references (corelib) match expected version
var ilcReferenceCommand = new GetValuesCommand(Log, projectPath, targetFramework, "IlcReference", GetValuesCommand.ValueType.Item)
var ilcReferenceCommand = new GetValuesCommand(testAsset, "IlcReference", GetValuesCommand.ValueType.Item, targetFramework)
{
DependsOnTargets = "WriteIlcRspFileForCompilation"
};
ilcReferenceCommand.Execute().Should().Pass();
var ilcReference = ilcReferenceCommand.GetValues();
var corelibReference = ilcReference.Where(r => Path.GetFileName(r).Equals("System.Private.CoreLib.dll")).Single();
var ilcReferenceVersion = Path.GetFileName(Path.GetDirectoryName(Path.GetDirectoryName(corelibReference)));
ilcReferenceVersion.Should().Be(ExplicitPackageVersion);
ilcReferenceVersion.Should().Be(expectedVersion);
}

private TestProject CreateHelloWorldTestProject(string targetFramework, string projectName, bool isExecutable)
Expand Down
7 changes: 7 additions & 0 deletions src/Tests/Microsoft.NET.Publish.Tests/PublishTestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ internal static class PublishTestUtils
new object[] { ToolsetInfo.CurrentTargetFramework },
new object[] { ToolsetInfo.NextTargetFramework }
};

// This list should contain all supported TFMs after net7.0
public static IEnumerable<object[]> Net7Plus { get; } = new List<object[]>
{
new object[] { ToolsetInfo.CurrentTargetFramework },
new object[] { ToolsetInfo.NextTargetFramework }
};
#else
#error If building for a newer TFM, please update the values above
#endif
Expand Down