diff --git a/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/DotNetSdkActions.cs b/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/DotNetSdkActions.cs index 3f2a0ba21..c97a21cda 100644 --- a/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/DotNetSdkActions.cs +++ b/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/DotNetSdkActions.cs @@ -16,4 +16,5 @@ public enum DotNetSdkActions PublishR2R = 32, Test = 64, AddClassLibRef = 128, + PublishAOT = 256, } diff --git a/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/DotNetSdkHelper.cs b/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/DotNetSdkHelper.cs index 19acb1a92..303f110cb 100644 --- a/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/DotNetSdkHelper.cs +++ b/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/DotNetSdkHelper.cs @@ -105,11 +105,16 @@ public string ExecuteNew(string projectType, string projectName, string projectD return projectDirectory; } - public void ExecutePublish(string projectDirectory, bool? selfContained = null, string? rid = null, bool trimmed = false, bool readyToRun = false, string[]? frameworks = null) + public void ExecutePublish(string projectDirectory, bool? selfContained = null, string? rid = null, bool trimmed = false, bool readyToRun = false, string[]? frameworks = null, bool aot = false) { string options = string.Empty; string binlogDifferentiator = string.Empty; - + + if ((trimmed || readyToRun || aot) && (selfContained.HasValue && selfContained.Value != true)) + { + throw new ArgumentException("Invalid test parameters: Trimmed and ReadyToRun can only be used with self-contained publish"); + } + if (selfContained.HasValue) { options += $"--self-contained {selfContained.Value.ToString().ToLowerInvariant()}"; @@ -130,6 +135,15 @@ public void ExecutePublish(string projectDirectory, bool? selfContained = null, { options += " /p:PublishReadyToRun=true"; binlogDifferentiator += "-R2R"; + if (aot) + { + throw new ArgumentException("Invalid Test parameters: Publish AOT cannot be used with ReadyToRun publish"); + } + } + if (aot) + { + options += " /p:PublishAOT=true"; + binlogDifferentiator += "-AOT"; } } } @@ -168,7 +182,7 @@ public void ExecuteRun(string projectDirectory, string[]? frameworks = null) public void ExecuteRunWeb(string projectDirectory) { - //checks what Process.Kill() will return based. Windows this is -1, Mac and Linux this appears + //checks what Process.Kill() will return based. Windows this is -1, Mac and Linux this appears //to be process based. Currently 137 int exitCode = OperatingSystemFinder.IsWindowsPlatform() ? -1 : 137; diff --git a/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/SdkTemplateTest.cs b/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/SdkTemplateTest.cs index 38f2b5827..fe62cb0e9 100644 --- a/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/SdkTemplateTest.cs +++ b/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/SdkTemplateTest.cs @@ -85,7 +85,7 @@ internal void Execute(DotNetSdkHelper dotNetHelper, string testRoot, string[]? f } if (Commands.HasFlag(DotNetSdkActions.PublishComplex)) { - dotNetHelper.ExecutePublish(projectDirectory, selfContained: false); + dotNetHelper.ExecutePublish(projectDirectory, selfContained: false); dotNetHelper.ExecutePublish(projectDirectory, selfContained: true, TargetRid); dotNetHelper.ExecutePublish(projectDirectory, selfContained: true, $"linux-{TargetArchitecture}"); } @@ -93,6 +93,10 @@ internal void Execute(DotNetSdkHelper dotNetHelper, string testRoot, string[]? f { dotNetHelper.ExecutePublish(projectDirectory, selfContained: true, $"linux-{TargetArchitecture}", trimmed: true, readyToRun: true); } + if (Commands.HasFlag(DotNetSdkActions.PublishAOT)) + { + dotNetHelper.ExecutePublish(projectDirectory, selfContained: true, TargetRid, aot: true); + } if (Commands.HasFlag(DotNetSdkActions.Test)) { dotNetHelper.ExecuteTest(projectDirectory); diff --git a/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/SdkTemplateTests.cs b/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/SdkTemplateTests.cs index 608cc9515..03125a855 100644 --- a/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/SdkTemplateTests.cs +++ b/src/Microsoft.DotNet.ScenarioTests.SdkTemplateTests/SdkTemplateTests.cs @@ -21,7 +21,7 @@ public SdkTemplateTests(ScenarioTestFixture testInput, ITestOutputHelper outputH _testOutputHelper = outputHelper; _sdkHelper = new DotNetSdkHelper(outputHelper, _scenarioTestInput.DotNetRoot, _scenarioTestInput.SdkVersion); } - + [Theory] [MemberData(nameof(GetLanguages))] public void VerifyConsoleTemplateComplex(DotNetLanguage language) @@ -32,6 +32,16 @@ public void VerifyConsoleTemplateComplex(DotNetLanguage language) newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot); } + [Theory] + [MemberData(nameof(GetLanguages))] + public void VerifyConsoleTemplateAOT(DotNetLanguage language) + { + var newTest = new SdkTemplateTest( + nameof(SdkTemplateTests) + "AOT", language, _scenarioTestInput.TargetRid, DotNetSdkTemplate.Console, + DotNetSdkActions.Build | DotNetSdkActions.Run | DotNetSdkActions.PublishAOT); + newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot); + } + [Theory] [MemberData(nameof(GetLanguages))] [Trait("Category", "Offline")] @@ -83,7 +93,7 @@ public void VerifyMSTestTemplate(DotNetLanguage language) DotNetSdkActions.Test); newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot); } - + [Theory] [InlineData(DotNetLanguage.CSharp)] [InlineData(DotNetLanguage.VB)] @@ -97,7 +107,7 @@ public void VerifyWPFTemplate(DotNetLanguage language) DotNetSdkActions.Test | DotNetSdkActions.Run | DotNetSdkActions.Publish); newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot); } - + [Fact] [Trait("Category", "Offline")] [Trait("SkipIfPlatform", "LINUX")] @@ -109,7 +119,7 @@ public void VerifyWebAppTemplate() DotNetSdkActions.Test | DotNetSdkActions.Run | DotNetSdkActions.Publish); newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot); } - + [Theory] [InlineData(DotNetLanguage.CSharp)] [InlineData(DotNetLanguage.VB)] @@ -123,7 +133,7 @@ public void VerifyWinformsTemplate(DotNetLanguage language) DotNetSdkActions.Test | DotNetSdkActions.Run | DotNetSdkActions.Publish); newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot); } - + [Theory] [InlineData(DotNetLanguage.CSharp)] [InlineData(DotNetLanguage.VB)] @@ -141,7 +151,7 @@ public void VerifyReferenceInConsoleTemplate(DotNetLanguage language) DotNetSdkActions.Run | DotNetSdkActions.Publish); newTest.Execute(_sdkHelper, _scenarioTestInput.TestRoot); } - + [Theory] [Trait("Category", "MultiTFM")] [Trait("Category", "Offline")] @@ -208,7 +218,7 @@ public void VerifyPreMadeSolution() } /* - * v-masche note: Requires ASP.NET runtimes for .NET6 and .NET7. To be enabled if we decide to + * v-masche note: Requires ASP.NET runtimes for .NET6 and .NET7. To be enabled if we decide to * download that as part of the build like we do the normal .NET runtimes [Fact] [Trait("Category", "MultiTFM")] @@ -235,7 +245,7 @@ public void VerifyDuplicateReferenceFailuresInConsoleTemplate(DotNetLanguage lan }*/ private static string[] GetFrameworks = { "net9.0", "net8.0", "net7.0", "net6.0" }; - + private static IEnumerable GetLanguages() => Enum.GetValues().Select(lang => new object[] { lang }); }