Skip to content

Commit e3d17f5

Browse files
authored
Add aot option to gRPC template (#46462)
1 parent 6a61c89 commit e3d17f5

20 files changed

+89
-5
lines changed

src/ProjectTemplates/Web.ProjectTemplates/GrpcService-CSharp.csproj.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<TargetFramework>${DefaultNetCoreTargetFramework}</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
7+
<!--#if (NativeAot) -->
8+
<PublishAot>true</PublishAot>
9+
<!--#endif -->
710
</PropertyGroup>
811

912
<ItemGroup>

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/.template.config/dotnetcli.host.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
"UseProgramMain": {
2222
"longName": "use-program-main",
2323
"shortName": ""
24+
},
25+
"NativeAot": {
26+
"longName": "publish-native-aot",
27+
"shortName": "aot"
2428
}
2529
},
2630
"usageExamples": [

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/.template.config/ide.host.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
"isVisible": true,
1010
"persistenceScope": "shared",
1111
"persistenceScopeName": "Microsoft"
12+
},
13+
{
14+
"id": "NativeAot",
15+
"isVisible": true
1216
}
1317
]
1418
}

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/.template.config/localize/templatestrings.cs.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"symbols/kestrelHttpsPort/description": "Číslo portu, který se má použít pro koncový bod HTTPS v souboru launchSettings.json. Tato možnost se dá použít jenom v případě, že se nepoužije parametr no-https (no-https se bude ignorovat, pokud se použije IndividualAuth nebo OrganizationalAuth).",
1111
"symbols/UseProgramMain/displayName": "Nepoužívat _příkazy nejvyšší úrovně",
1212
"symbols/UseProgramMain/description": "Určuje, jestli se má místo příkazů nejvyšší úrovně generovat explicitní třída Program a metoda Main.",
13+
"symbols/NativeAot/displayName": "Enable _native AOT publish",
14+
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
1315
"postActions/restore/description": "Obnoví balíčky NuGet vyžadované tímto projektem.",
1416
"postActions/restore/manualInstructions/default/text": "Spustit dotnet restore"
1517
}

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/.template.config/localize/templatestrings.de.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"symbols/kestrelHttpsPort/description": "Portnummer, die für den HTTPS Endpunkt in launchSettings.json verwendet werden soll. Diese Option ist nur anwendbar, wenn der Parameter no-https nicht verwendet wird (no-https wird ignoriert, wenn entweder IndividualAuth oder OrganizationalAuth verwendet wird).",
1111
"symbols/UseProgramMain/displayName": "Keine Anweisungen_der obersten Ebene verwenden",
1212
"symbols/UseProgramMain/description": "Gibt an, ob anstelle von Anweisungen der obersten Ebene eine explizite Programmklasse und eine Main-Methode generiert werden soll.",
13+
"symbols/NativeAot/displayName": "Enable _native AOT publish",
14+
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
1315
"postActions/restore/description": "„NuGet-Pakete“ wiederherstellen, die für dieses Projekt erforderlich sind.",
1416
"postActions/restore/manualInstructions/default/text": "„dotnet restore“ ausführen"
1517
}

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/.template.config/localize/templatestrings.en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"symbols/UseProgramMain/displayName": "Do not use _top-level statements",
1313
"_symbols/UseProgramMain/displayName.comment": "Use '_' as accelerator key when translating.",
1414
"symbols/UseProgramMain/description": "Whether to generate an explicit Program class and Main method instead of top-level statements.",
15+
"symbols/NativeAot/displayName": "Enable _native AOT publish",
16+
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
1517
"postActions/restore/description": "Restore NuGet packages required by this project.",
1618
"postActions/restore/manualInstructions/default/text": "Run 'dotnet restore'"
1719
}

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/.template.config/localize/templatestrings.es.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"symbols/kestrelHttpsPort/description": "Número de puerto que se va a usar para el punto de conexión HTTPS en launchSettings.json. Esta opción solo es aplicable cuando no se usa el parámetro no-https (no-https se omitirá si se usa IndividualAuth o OrganizationalAuth).",
1111
"symbols/UseProgramMain/displayName": "No usar instrucciones de _nivel superior",
1212
"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.",
13+
"symbols/NativeAot/displayName": "Enable _native AOT publish",
14+
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
1315
"postActions/restore/description": "Restaure los paquetes NuGet necesarios para este proyecto.",
1416
"postActions/restore/manualInstructions/default/text": "Ejecutar \"dotnet restore\""
1517
}

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/.template.config/localize/templatestrings.fr.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"symbols/kestrelHttpsPort/description": "Numéro de port à utiliser pour le point de terminaison HTTPS dans launchSettings.json. Cette option s’applique uniquement lorsque le paramètre no-https n’est pas utilisé (no-https sera ignoré si IndividualAuth ou OrganizationalAuth est utilisé).",
1111
"symbols/UseProgramMain/displayName": "N’utilisez pas _d’instructions de niveau supérieur.",
1212
"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.",
13+
"symbols/NativeAot/displayName": "Enable _native AOT publish",
14+
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
1315
"postActions/restore/description": "Restaurez les packages NuGet requis par ce projet.",
1416
"postActions/restore/manualInstructions/default/text": "Exécuter « dotnet restore »"
1517
}

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/.template.config/localize/templatestrings.it.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"symbols/kestrelHttpsPort/description": "Numero di porta da usare per l'endpoint HTTPS in launchSettings.json. Questa opzione è applicabile solo quando il parametro no-https non viene usato (no-https verrà ignorato se si usa IndividualAuth o OrganizationalAuth).",
1111
"symbols/UseProgramMain/displayName": "Non usare_istruzioni di primo livello",
1212
"symbols/UseProgramMain/description": "Indica se generare una classe Program esplicita e un metodo Main anziché istruzioni di primo livello.",
13+
"symbols/NativeAot/displayName": "Enable _native AOT publish",
14+
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
1315
"postActions/restore/description": "Ripristina i pacchetti NuGet richiesti da questo progetto.",
1416
"postActions/restore/manualInstructions/default/text": "Esegui 'dotnet restore'"
1517
}

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/.template.config/localize/templatestrings.ja.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"symbols/kestrelHttpsPort/description": "launchSettings.json で HTTPS エンドポイントに使用するポート番号。このオプションは、HTTPS 以外のパラメーターが使用されていない場合にのみ適用されます (IndividualAuth または OrganizationalAuth が使用されている場合は、HTTPS 以外は無視されます)。",
1111
"symbols/UseProgramMain/displayName": "最上位レベルのステートメントを使用しない(_T)",
1212
"symbols/UseProgramMain/description": "最上位レベルのステートメントではなく、明示的な Program クラスと Main メソッドを生成するかどうか。",
13+
"symbols/NativeAot/displayName": "Enable _native AOT publish",
14+
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
1315
"postActions/restore/description": "このプロジェクトに必要な NuGet パッケージを復元します。",
1416
"postActions/restore/manualInstructions/default/text": "'dotnet restore' を実行する"
1517
}

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/.template.config/localize/templatestrings.ko.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"symbols/kestrelHttpsPort/description": "launchSettings.json의 HTTPS 엔드포인트에 사용할 포트 번호입니다. 이 옵션은 매개 변수 no-https가 사용되지 않은 경우에만 적용됩니다(IndividualAuth 또는 OrganizationalAuth가 사용되는 경우 no-https는 무시됨).",
1111
"symbols/UseProgramMain/displayName": "최상위 문 사용 안 함(_T)",
1212
"symbols/UseProgramMain/description": "최상위 문 대신 명시적 Program 클래스 및 Main 메서드를 생성할지 여부입니다.",
13+
"symbols/NativeAot/displayName": "Enable _native AOT publish",
14+
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
1315
"postActions/restore/description": "이 프로젝트에 필요한 NuGet 패키지를 복원합니다.",
1416
"postActions/restore/manualInstructions/default/text": "'dotnet restore' 실행"
1517
}

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/.template.config/localize/templatestrings.pl.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"symbols/kestrelHttpsPort/description": "Numer portu do użycia dla punktu końcowego HTTPS w pliku launchSettings.json. Ta opcja ma zastosowanie tylko wtedy, gdy parametr no-https nie jest używany (parametr no-https zostanie zignorowany, jeśli zostanie użyte uwierzytelnianie IndividualAuth lub OrganizationalAuth).",
1111
"symbols/UseProgramMain/displayName": "Nie używaj ins_trukcji najwyższego poziomu",
1212
"symbols/UseProgramMain/description": "Określa, czy wygenerować jawną klasę Program i metodę Main zamiast instrukcji najwyższego poziomu.",
13+
"symbols/NativeAot/displayName": "Enable _native AOT publish",
14+
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
1315
"postActions/restore/description": "Przywróć pakiety NuGet wymagane przez ten projekt.",
1416
"postActions/restore/manualInstructions/default/text": "Uruchom polecenie \"dotnet restore\""
1517
}

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/.template.config/localize/templatestrings.pt-BR.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"symbols/kestrelHttpsPort/description": "Número da porta a ser usada para o ponto de extremidade HTTPS em launchSettings.json. Essa opção só é aplicável quando o parâmetro no-https não é usado (no-https será ignorado se IndividualAuth ou OrganizationalAuth for usado).",
1111
"symbols/UseProgramMain/displayName": "Não use ins_truções de nível superior",
1212
"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.",
13+
"symbols/NativeAot/displayName": "Enable _native AOT publish",
14+
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
1315
"postActions/restore/description": "Restaure os pacotes NuGet exigidos por este projeto.",
1416
"postActions/restore/manualInstructions/default/text": "Executar 'dotnet restore'"
1517
}

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/.template.config/localize/templatestrings.ru.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"symbols/kestrelHttpsPort/description": "Номер порта, используемый для конечной точки HTTPS в launchSettings.json. Этот параметр применим только в том случае, если no-https не используется (при использовании IndividualAuth или OrganizationalAuth no-https игнорируется).",
1111
"symbols/UseProgramMain/displayName": "Не использовать _операторы верхнего уровня",
1212
"symbols/UseProgramMain/description": "Следует ли создавать явный класс Program и метод Main вместо операторов верхнего уровня.",
13+
"symbols/NativeAot/displayName": "Enable _native AOT publish",
14+
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
1315
"postActions/restore/description": "Восстановление пакетов NuGet, необходимых для этого проекта.",
1416
"postActions/restore/manualInstructions/default/text": "Выполнить команду \"dotnet restore\""
1517
}

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/.template.config/localize/templatestrings.tr.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"symbols/kestrelHttpsPort/description": "launchSettings.json içinde HTTPS uç noktası için kullanılacak bağlantı noktası numarası. Bu seçenek yalnızca no-https parametresi kullanılmazsa uygulanabilir (IndividualAuth veya OrganizationalAuth kullanılırsa no-https yoksayılır).",
1111
"symbols/UseProgramMain/displayName": "_Üst düzey deyimler kullanmayın",
1212
"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.",
13+
"symbols/NativeAot/displayName": "Enable _native AOT publish",
14+
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
1315
"postActions/restore/description": "Bu projenin gerektirdiği NuGet paketlerini geri yükleyin.",
1416
"postActions/restore/manualInstructions/default/text": "'dotnet restore' çalıştır"
1517
}

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/.template.config/localize/templatestrings.zh-Hans.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"symbols/kestrelHttpsPort/description": "要用于 launchSettings.json 中 HTTPS 终结点的端口号。仅当不使用参数 no-https 时,此选项才适用(如果使用 IndividualAuth 或 OrganizationalAuth,则将忽略 no-https)。",
1111
"symbols/UseProgramMain/displayName": "不使用顶级语句(_T)",
1212
"symbols/UseProgramMain/description": "是否生成显式程序类和主方法,而不是顶级语句。",
13+
"symbols/NativeAot/displayName": "Enable _native AOT publish",
14+
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
1315
"postActions/restore/description": "还原此项目所需的 NuGet 包。",
1416
"postActions/restore/manualInstructions/default/text": "运行 \"dotnet restore\""
1517
}

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/.template.config/localize/templatestrings.zh-Hant.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"symbols/kestrelHttpsPort/description": "launchSettings.json 中 HTTPS 端點要使用的連接埠號碼。只有在未使用參數 no-https 時,才適用此選項 (如果使用 IndividualAuth 或 OrganizationalAuth,則會忽略 no-https)。",
1111
"symbols/UseProgramMain/displayName": "不要使用最上層陳述式(_T)",
1212
"symbols/UseProgramMain/description": "是否要產生明確的 Program 類別和 Main 方法,而非最上層語句。",
13+
"symbols/NativeAot/displayName": "Enable _native AOT publish",
14+
"symbols/NativeAot/description": "Whether to enable the project for publishing as native AOT.",
1315
"postActions/restore/description": "還原此專案所需的 NuGet 套件。",
1416
"postActions/restore/manualInstructions/default/text": "執行 'dotnet restore'"
1517
}

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/.template.config/template.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@
124124
"defaultValue": "false",
125125
"displayName": "Do not use _top-level statements",
126126
"description": "Whether to generate an explicit Program class and Main method instead of top-level statements."
127+
},
128+
"NativeAot" : {
129+
"type": "parameter",
130+
"datatype": "bool",
131+
"defaultValue": "false",
132+
"displayName": "Enable _native AOT publish",
133+
"description": "Whether to enable the project for publishing as native AOT."
127134
}
128135
},
129136
"primaryOutputs": [
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env pwsh
2+
#requires -version 4
3+
4+
[CmdletBinding(PositionalBinding = $false)]
5+
param()
6+
7+
Set-StrictMode -Version 2
8+
$ErrorActionPreference = 'Stop'
9+
10+
. $PSScriptRoot\Test-Template.ps1
11+
12+
Test-Template "grpc" "grpc -aot" "Microsoft.DotNet.Web.ProjectTemplates.8.0.8.0.0-dev.nupkg" $false

src/ProjectTemplates/test/Templates.Tests/GrpcTemplateTest.cs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,42 @@ public ITestOutputHelper Output
3434
}
3535
}
3636

37-
[ConditionalTheory]
37+
[ConditionalFact]
3838
[SkipOnHelix("Not supported queues", Queues = "windows.11.arm64.open;" + HelixConstants.Windows10Arm64 + HelixConstants.DebianArm64)]
3939
[SkipOnAlpine("https://github.com/grpc/grpc/issues/18338")]
40-
[InlineData(true)]
41-
[InlineData(false)]
42-
public async Task GrpcTemplate(bool useProgramMain)
40+
public async Task GrpcTemplate()
41+
{
42+
await GrpcTemplateCore();
43+
}
44+
45+
[ConditionalFact(Skip = "Unskip when there are no more build or publish warnings for native AOT.")]
46+
[SkipOnHelix("Not supported queues", Queues = "windows.11.arm64.open;" + HelixConstants.Windows10Arm64 + HelixConstants.DebianArm64)]
47+
[SkipOnAlpine("https://github.com/grpc/grpc/issues/18338")]
48+
public async Task GrpcTemplateNativeAot()
49+
{
50+
await GrpcTemplateCore(args: new[] { ArgConstants.PublishNativeAot });
51+
}
52+
53+
[ConditionalFact]
54+
[SkipOnHelix("Not supported queues", Queues = "windows.11.arm64.open;" + HelixConstants.Windows10Arm64 + HelixConstants.DebianArm64)]
55+
[SkipOnAlpine("https://github.com/grpc/grpc/issues/18338")]
56+
public async Task GrpcTemplateProgramMain()
57+
{
58+
await GrpcTemplateCore(args: new[] { ArgConstants.UseProgramMain });
59+
}
60+
61+
[ConditionalFact(Skip = "Unskip when there are no more build or publish warnings for native AOT.")]
62+
[SkipOnHelix("Not supported queues", Queues = "windows.11.arm64.open;" + HelixConstants.Windows10Arm64 + HelixConstants.DebianArm64)]
63+
[SkipOnAlpine("https://github.com/grpc/grpc/issues/18338")]
64+
public async Task GrpcTemplateProgramMainNativeAot()
65+
{
66+
await GrpcTemplateCore(args: new[] { ArgConstants.UseProgramMain, ArgConstants.PublishNativeAot });
67+
}
68+
69+
private async Task GrpcTemplateCore(string[] args = null)
4370
{
4471
var project = await ProjectFactory.CreateProject(Output);
4572

46-
var args = useProgramMain ? new[] { ArgConstants.UseProgramMain } : null;
4773
await project.RunDotNetNewAsync("grpc", args: args);
4874

4975
var expectedLaunchProfileNames = new[] { "http", "https" };

0 commit comments

Comments
 (0)