Skip to content

Commit

Permalink
Add AOT flag to worker template (dotnet#47721)
Browse files Browse the repository at this point in the history
* Add AOT flag to worker template

Fix dotnet#46541

* Update Worker template tests for NativeAOT.

Fix Api template tests for NativeAOT to pass locally.
  • Loading branch information
eerhardt authored Apr 19, 2023
1 parent 02345dc commit cd711c2
Show file tree
Hide file tree
Showing 42 changed files with 190 additions and 26 deletions.
8 changes: 1 addition & 7 deletions src/ProjectTemplates/Shared/AspNetProcess.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
// 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.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Security;
using System.Threading.Tasks;
using AngleSharp.Dom.Html;
using AngleSharp.Parser.Html;
using Microsoft.AspNetCore.Internal;
Expand All @@ -18,7 +13,6 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Playwright;
using Xunit;
using Xunit.Abstractions;

namespace Templates.Test.Helpers;
Expand Down Expand Up @@ -66,7 +60,7 @@ public AspNetProcess(
{
if (usePublishedAppHost)
{
// When publishingu used the app host to run the app. This makes it easy to consistently run for regular and single-file publish
// When publishing, use the app host to run the app. This makes it easy to consistently run for regular and single-file publish
process = Path.ChangeExtension(dllPath, OperatingSystem.IsWindows() ? ".exe" : null);
arguments = null;
}
Expand Down
54 changes: 46 additions & 8 deletions src/ProjectTemplates/Shared/Project.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
// 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.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Internal;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.CommandLineUtils;
using Microsoft.Extensions.Logging;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
using static Templates.Test.Helpers.ProcessLock;

namespace Templates.Test.Helpers;

Expand Down Expand Up @@ -363,6 +356,51 @@ public async Task VerifyHasProperty(string propertyName, string expectedValue)
Assert.Contains($"<{propertyName}>{expectedValue}</{propertyName}>", projectFileContents);
}

public void SetCurrentRuntimeIdentifier()
{
RuntimeIdentifier = GetRuntimeIdentifier();

static string GetRuntimeIdentifier()
{
// we need to use the "portable" RID (win-x64), not the actual RID (win10-x64)
return $"{GetOS()}-{GetArchitecture()}";
}

static string GetOS()
{
if (OperatingSystem.IsWindows())
{
return "win";
}
if (OperatingSystem.IsLinux())
{
return "linux";
}
if (OperatingSystem.IsMacOS())
{
return "osx";
}
throw new NotSupportedException();
}

static string GetArchitecture()
{
switch (RuntimeInformation.ProcessArchitecture)
{
case Architecture.X86:
return "x86";
case Architecture.X64:
return "x64";
case Architecture.Arm:
return "arm";
case Architecture.Arm64:
return "arm64";
default:
throw new NotSupportedException();
}
}
}

public string ReadFile(string path)
{
AssertFileExists(path, shouldExist: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<PropertyGroup>
<RestoreAdditionalProjectSources>${RestoreAdditionalProjectSources}</RestoreAdditionalProjectSources>
<!-- This sets an option which prevents the tests from rolling forward into a newer shared framework. -->
<UserRuntimeConfig>$(MSBuildThisFileDirectory)runtimeconfig.norollforward.json</UserRuntimeConfig>
<UserRuntimeConfig Condition="'$(PublishAot)' != 'true'">$(MSBuildThisFileDirectory)runtimeconfig.norollforward.json</UserRuntimeConfig>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<!--#if (NativeAot) -->
<PublishAot>true</PublishAot>
<StripSymbols>true</StripSymbols>
<!--#endif -->
<UserSecretsId>dotnet-Company.Application1-53bc9b9d-9d6a-45d4-8429-2a2761773502</UserSecretsId>
<NoDefaultLaunchSettingsFile Condition="'$(ExcludeLaunchSettings)' == 'True'">True</NoDefaultLaunchSettingsFile>
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">Company.Application1</RootNamespace>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<TargetFramework>${DefaultNetCoreTargetFramework}</TargetFramework>
<UserSecretsId>dotnet-Company.Application1-53bc9b9d-9d6a-45d4-8429-2a2761773502</UserSecretsId>
<InvariantGlobalization>true</InvariantGlobalization>
<!--#if (NativeAot) -->
<PublishAot>true</PublishAot>
<StripSymbols>true</StripSymbols>
<!--#endif -->
<NoDefaultLaunchSettingsFile Condition="'$(ExcludeLaunchSettings)' == 'True'">True</NoDefaultLaunchSettingsFile>
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">Company.Application1</RootNamespace>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"UseProgramMain": {
"longName": "use-program-main",
"shortName": ""
},
"NativeAot": {
"longName": "publish-native-aot",
"shortName": "aot"
}
},
"usageExamples": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"isVisible": true,
"persistenceScope": "shared",
"persistenceScopeName": "Microsoft"
},
{
"id": "NativeAot",
"isVisible": true
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"symbols/skipRestore/description": "Pokud se tato možnost zadá, přeskočí automatické obnovení projektu při vytvoření.",
"symbols/UseProgramMain/displayName": "Nepoužívat _příkazy nejvyšší úrovně",
"symbols/UseProgramMain/description": "Určuje, jestli se má místo příkazů nejvyšší úrovně generovat explicitní třída Program a metoda Main.",
"symbols/NativeAot/displayName": "Enable _native AOT publish",
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
"postActions/restore/description": "Obnoví balíčky NuGet vyžadované tímto projektem.",
"postActions/restore/manualInstructions/default/text": "Spustit dotnet restore"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"symbols/skipRestore/description": "Wenn angegeben, wird die automatische Wiederherstellung des Projekts beim Erstellen übersprungen.",
"symbols/UseProgramMain/displayName": "Keine Anweisungen_der obersten Ebene verwenden",
"symbols/UseProgramMain/description": "Gibt an, ob anstelle von Anweisungen der obersten Ebene eine explizite Programmklasse und eine Main-Methode generiert werden soll.",
"symbols/NativeAot/displayName": "Enable _native AOT publish",
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
"postActions/restore/description": "„NuGet-Pakete“ wiederherstellen, die für dieses Projekt erforderlich sind.",
"postActions/restore/manualInstructions/default/text": "„dotnet restore“ ausführen"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"symbols/UseProgramMain/displayName": "Do not use _top-level statements",
"_symbols/UseProgramMain/displayName.comment": "Use '_' as accelerator key when translating.",
"symbols/UseProgramMain/description": "Whether to generate an explicit Program class and Main method instead of top-level statements.",
"symbols/NativeAot/displayName": "Enable _native AOT publish",
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
"postActions/restore/description": "Restore NuGet packages required by this project.",
"postActions/restore/manualInstructions/default/text": "Run 'dotnet restore'"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"symbols/skipRestore/description": "Si se especifica, se omite la restauración automática del proyecto durante la creación.",
"symbols/UseProgramMain/displayName": "No usar instrucciones de _nivel superior",
"symbols/UseProgramMain/description": "Indica si se debe generar una clase Program explícita y un método Main en lugar de instrucciones de nivel superior.",
"symbols/NativeAot/displayName": "Enable _native AOT publish",
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
"postActions/restore/description": "Restaure los paquetes NuGet necesarios para este proyecto.",
"postActions/restore/manualInstructions/default/text": "Ejecutar \"dotnet restore\""
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"symbols/skipRestore/description": "S’il est spécifié, ignore la restauration automatique du projet lors de la création.",
"symbols/UseProgramMain/displayName": "N’utilisez pas _d’instructions de niveau supérieur.",
"symbols/UseProgramMain/description": "Indique s’il faut générer une classe Programme explicite et une méthode Main au lieu d’instructions de niveau supérieur.",
"symbols/NativeAot/displayName": "Enable _native AOT publish",
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
"postActions/restore/description": "Restaurez les packages NuGet requis par ce projet.",
"postActions/restore/manualInstructions/default/text": "Exécuter « dotnet restore »"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"symbols/skipRestore/description": "Se specificato, ignora il ripristino automatico del progetto durante la creazione.",
"symbols/UseProgramMain/displayName": "Non usare_istruzioni di primo livello",
"symbols/UseProgramMain/description": "Indica se generare una classe Program esplicita e un metodo Main anziché istruzioni di primo livello.",
"symbols/NativeAot/displayName": "Enable _native AOT publish",
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
"postActions/restore/description": "Ripristina i pacchetti NuGet richiesti da questo progetto.",
"postActions/restore/manualInstructions/default/text": "Esegui 'dotnet restore'"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"symbols/skipRestore/description": "指定した場合、作成時にプロジェクトの自動復元がスキップされます。",
"symbols/UseProgramMain/displayName": "最上位レベルのステートメントを使用しない(_T)",
"symbols/UseProgramMain/description": "最上位レベルのステートメントではなく、明示的な Program クラスと Main メソッドを生成するかどうか。",
"symbols/NativeAot/displayName": "Enable _native AOT publish",
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
"postActions/restore/description": "このプロジェクトに必要な NuGet パッケージを復元します。",
"postActions/restore/manualInstructions/default/text": "'dotnet restore' を実行する"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"symbols/skipRestore/description": "지정된 경우, 프로젝트 생성 시 자동 복원을 건너뜁니다.",
"symbols/UseProgramMain/displayName": "최상위 문 사용 안 함(_T)",
"symbols/UseProgramMain/description": "최상위 문 대신 명시적 Program 클래스 및 Main 메서드를 생성할지 여부입니다.",
"symbols/NativeAot/displayName": "Enable _native AOT publish",
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
"postActions/restore/description": "이 프로젝트에 필요한 NuGet 패키지를 복원합니다.",
"postActions/restore/manualInstructions/default/text": "'dotnet restore' 실행"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"symbols/skipRestore/description": "Jeśli ta opcja jest określona, pomija automatyczne przywracanie projektu podczas tworzenia.",
"symbols/UseProgramMain/displayName": "Nie używaj ins_trukcji najwyższego poziomu",
"symbols/UseProgramMain/description": "Określa, czy wygenerować jawną klasę Program i metodę Main zamiast instrukcji najwyższego poziomu.",
"symbols/NativeAot/displayName": "Enable _native AOT publish",
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
"postActions/restore/description": "Przywróć pakiety NuGet wymagane przez ten projekt.",
"postActions/restore/manualInstructions/default/text": "Uruchom polecenie \"dotnet restore\""
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"symbols/skipRestore/description": "Se especificado, ignora a restauração automática do projeto sendo criado.",
"symbols/UseProgramMain/displayName": "Não use ins_truções de nível superior",
"symbols/UseProgramMain/description": "Se deve gerar uma classe de Programa explícita e um método principal em vez de instruções de nível superior.",
"symbols/NativeAot/displayName": "Enable _native AOT publish",
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
"postActions/restore/description": "Restaure os pacotes NuGet exigidos por este projeto.",
"postActions/restore/manualInstructions/default/text": "Executar 'dotnet restore'"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"symbols/skipRestore/description": "Если установлено, автоматическое восстановление проекта при создании пропускается.",
"symbols/UseProgramMain/displayName": "Не использовать _операторы верхнего уровня",
"symbols/UseProgramMain/description": "Следует ли создавать явный класс Program и метод Main вместо операторов верхнего уровня.",
"symbols/NativeAot/displayName": "Enable _native AOT publish",
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
"postActions/restore/description": "Восстановление пакетов NuGet, необходимых для этого проекта.",
"postActions/restore/manualInstructions/default/text": "Выполнить команду \"dotnet restore\""
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"symbols/skipRestore/description": "Belirtilirse, oluşturma sırasında projenin otomatik geri yüklenmesini atlar.",
"symbols/UseProgramMain/displayName": "_Üst düzey deyimler kullanmayın",
"symbols/UseProgramMain/description": "Üst düzey deyimler yerine açık bir Program sınıfı ve Ana yöntem oluşturup oluşturulmayacağını belirtir.",
"symbols/NativeAot/displayName": "Enable _native AOT publish",
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
"postActions/restore/description": "Bu projenin gerektirdiği NuGet paketlerini geri yükleyin.",
"postActions/restore/manualInstructions/default/text": "'dotnet restore' çalıştır"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"symbols/skipRestore/description": "如果指定,则在创建时跳过项目的自动还原。",
"symbols/UseProgramMain/displayName": "不使用顶级语句(_T)",
"symbols/UseProgramMain/description": "是否生成显式程序类和主方法,而不是顶级语句。",
"symbols/NativeAot/displayName": "Enable _native AOT publish",
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
"postActions/restore/description": "还原此项目所需的 NuGet 包。",
"postActions/restore/manualInstructions/default/text": "运行 \"dotnet restore\""
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"symbols/skipRestore/description": "若指定,會在建立時跳過專案的自動還原。",
"symbols/UseProgramMain/displayName": "不要使用最上層陳述式(_T)",
"symbols/UseProgramMain/description": "是否要產生明確的 Program 類別和 Main 方法,而非最上層語句。",
"symbols/NativeAot/displayName": "Enable _native AOT publish",
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
"postActions/restore/description": "還原此專案所需的 NuGet 套件。",
"postActions/restore/manualInstructions/default/text": "執行 'dotnet restore'"
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@
"defaultValue": "false",
"displayName": "Do not use _top-level statements",
"description": "Whether to generate an explicit Program class and Main method instead of top-level statements."
},
"NativeAot" : {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"displayName": "Enable _native AOT publish",
"description": "Whether to enable the project for publishing as native AOT."
}
},
"primaryOutputs": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"ExcludeLaunchSettings": {
"longName": "exclude-launch-settings",
"shortName": ""
},
"NativeAot": {
"longName": "publish-native-aot",
"shortName": "aot"
}
},
"usageExamples": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
"$schema": "http://json.schemastore.org/ide.host",
"order": 300,
"icon": "ide/Worker.png",
"supportsDocker": true
"supportsDocker": true,
"symbolInfo": [
{
"id": "NativeAot",
"isVisible": true
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"symbols/Framework/description": "Cílová architektura pro projekt",
"symbols/Framework/choices/net8.0/description": "Cílový net8.0",
"symbols/skipRestore/description": "Pokud se tato možnost zadá, přeskočí automatické obnovení projektu při vytvoření.",
"symbols/NativeAot/displayName": "Enable _native AOT publish",
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
"postActions/restore/description": "Obnoví balíčky NuGet vyžadované tímto projektem.",
"postActions/restore/manualInstructions/default/text": "Spustit dotnet restore"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"symbols/Framework/description": "Das Zielframework für das Projekt.",
"symbols/Framework/choices/net8.0/description": "Ziel net8.0",
"symbols/skipRestore/description": "Wenn angegeben, wird die automatische Wiederherstellung des Projekts beim Erstellen übersprungen.",
"symbols/NativeAot/displayName": "Enable _native AOT publish",
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
"postActions/restore/description": "„NuGet-Pakete“ wiederherstellen, die für dieses Projekt erforderlich sind.",
"postActions/restore/manualInstructions/default/text": "„dotnet restore“ ausführen"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"symbols/Framework/choices/net8.0/description": "Target net8.0",
"_symbols/Framework/choices/net8.0/description.comment": "{Locked='net8.0'}",
"symbols/skipRestore/description": "If specified, skips the automatic restore of the project on create.",
"symbols/NativeAot/displayName": "Enable _native AOT publish",
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
"postActions/restore/description": "Restore NuGet packages required by this project.",
"postActions/restore/manualInstructions/default/text": "Run 'dotnet restore'"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"symbols/Framework/description": "Marco de destino del proyecto.",
"symbols/Framework/choices/net8.0/description": "net8.0 de destino",
"symbols/skipRestore/description": "Si se especifica, se omite la restauración automática del proyecto durante la creación.",
"symbols/NativeAot/displayName": "Enable _native AOT publish",
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
"postActions/restore/description": "Restaure los paquetes NuGet necesarios para este proyecto.",
"postActions/restore/manualInstructions/default/text": "Ejecutar \"dotnet restore\""
}
Loading

0 comments on commit cd711c2

Please sign in to comment.