diff --git a/src/Tasks/Common/Resources/Strings.resx b/src/Tasks/Common/Resources/Strings.resx index c0223eb3d6bb..ec6f8dd9db05 100644 --- a/src/Tasks/Common/Resources/Strings.resx +++ b/src/Tasks/Common/Resources/Strings.resx @@ -556,4 +556,8 @@ The following are names of parameters or literal values and should not be transl NETSDK1112: The runtime pack for {0} was not downloaded. Try running a NuGet restore with the RuntimeIdentifier '{1}'. {StrBegin="NETSDK1112: "} + + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + {StrBegin="NETSDK1113: "} + \ No newline at end of file diff --git a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf index 7682629eedc0..2590530b64a1 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf @@ -12,6 +12,11 @@ NETSDK1070: Konfigurační soubor aplikace musí obsahovat kořenový element konfigurace. {StrBegin="NETSDK1070: "} + + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + {StrBegin="NETSDK1113: "} + NETSDK1074: The application host executable will not be customized because adding resources requires that the build be performed on Windows (excluding Nano Server). NETSDK1074: Spustitelný soubor hostitele aplikace se nepřizpůsobí, protože přidávání prostředků vyžaduje, aby se sestavení provedlo na Windows (bez Nano Serveru). diff --git a/src/Tasks/Common/Resources/xlf/Strings.de.xlf b/src/Tasks/Common/Resources/xlf/Strings.de.xlf index cde2a8fdcc00..ddc0f9fcba4d 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.de.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.de.xlf @@ -12,6 +12,11 @@ NETSDK1070: Die Anwendungskonfigurationsdatei muss das Stammkonfigurationselement enthalten. {StrBegin="NETSDK1070: "} + + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + {StrBegin="NETSDK1113: "} + NETSDK1074: The application host executable will not be customized because adding resources requires that the build be performed on Windows (excluding Nano Server). NETSDK1074: Die ausführbare Anwendungshostdatei wird nicht angepasst, weil für das Hinzufügen von Ressourcen eine Ausführung des Builds unter Windows erforderlich ist (Nano Server ausgeschlossen). diff --git a/src/Tasks/Common/Resources/xlf/Strings.es.xlf b/src/Tasks/Common/Resources/xlf/Strings.es.xlf index 2bb42f14e2c0..23a9607e22fe 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.es.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.es.xlf @@ -12,6 +12,11 @@ NETSDK1070: El archivo de configuración de la aplicación debe tener el elemento de configuración raíz. {StrBegin="NETSDK1070: "} + + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + {StrBegin="NETSDK1113: "} + NETSDK1074: The application host executable will not be customized because adding resources requires that the build be performed on Windows (excluding Nano Server). NETSDK1074: El ejecutable del host de aplicación no se personalizará porque para agregar recursos es necesario que la compilación se realice en Windows (excepto Nano Server). diff --git a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf index 74c321dd4a0c..ccf83330bcd8 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf @@ -12,6 +12,11 @@ NETSDK1070: Le fichier de configuration de l'application doit avoir un élément de configuration racine. {StrBegin="NETSDK1070: "} + + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + {StrBegin="NETSDK1113: "} + NETSDK1074: The application host executable will not be customized because adding resources requires that the build be performed on Windows (excluding Nano Server). NETSDK1074: l'exécutable d'hôte d'application ne sera pas personnalisé, car l'ajout de ressources nécessite l'exécution de la génération sur Windows (à l'exception de Nano Server). diff --git a/src/Tasks/Common/Resources/xlf/Strings.it.xlf b/src/Tasks/Common/Resources/xlf/Strings.it.xlf index dc1e4faa3a94..409fe8b88b1b 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.it.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.it.xlf @@ -12,6 +12,11 @@ NETSDK1070: il file di configurazione dell'applicazione deve avere un elemento di configurazione radice. {StrBegin="NETSDK1070: "} + + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + {StrBegin="NETSDK1113: "} + NETSDK1074: The application host executable will not be customized because adding resources requires that the build be performed on Windows (excluding Nano Server). NETSDK1074: l'eseguibile dell'host applicazione non verrà personalizzato perché per aggiungere risorse è necessario eseguire la compilazione in Windows (escluso Nano Server). diff --git a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf index 191068c77298..ab9c40c828e3 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf @@ -12,6 +12,11 @@ NETSDK1070: アプリケーション構成ファイルには、ルート構成要素が必要です。 {StrBegin="NETSDK1070: "} + + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + {StrBegin="NETSDK1113: "} + NETSDK1074: The application host executable will not be customized because adding resources requires that the build be performed on Windows (excluding Nano Server). NETSDK1074: リソースの追加ではビルドが Windows 上で実行される必要があるため、アプリケーション ホストの実行可能ファイルはカスタマイズされません (Nano Server を除く)。 diff --git a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf index f6de7d90b737..3c96b8a954af 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf @@ -12,6 +12,11 @@ NETSDK1070: 애플리케이션 구성 파일에는 루트 구성 요소가 있어야 합니다. {StrBegin="NETSDK1070: "} + + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + {StrBegin="NETSDK1113: "} + NETSDK1074: The application host executable will not be customized because adding resources requires that the build be performed on Windows (excluding Nano Server). NETSDK1074: 리소스를 추가하려면 빌드가 Windows(Nano Server 제외)에서 수행되어야 하므로 애플리케이션 호스트 실행 파일이 사용자 지정되지 않습니다. diff --git a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf index a5202c3f7009..778f62d7f0cf 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf @@ -12,6 +12,11 @@ NETSDK1070: Plik konfiguracji aplikacji musi mieć główny element konfiguracji. {StrBegin="NETSDK1070: "} + + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + {StrBegin="NETSDK1113: "} + NETSDK1074: The application host executable will not be customized because adding resources requires that the build be performed on Windows (excluding Nano Server). NETSDK1074: Plik wykonywalny hosta aplikacji nie zostanie dostosowany, ponieważ dodawanie zasobów wymaga, aby kompilacja została wykonana w systemie Windows (z wyjątkiem systemu Nano Server). diff --git a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf index 835ca4b5cc5e..0ce70f87e920 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf @@ -12,6 +12,11 @@ NETSDK1070: o arquivo de configuração do aplicativo deve ter um elemento de configuração raiz. {StrBegin="NETSDK1070: "} + + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + {StrBegin="NETSDK1113: "} + NETSDK1074: The application host executable will not be customized because adding resources requires that the build be performed on Windows (excluding Nano Server). NETSDK1074: o host do aplicativo executável não será personalizado porque a adição de recursos requer que o build seja executado no Windows (excluindo Nano Server). diff --git a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf index 8a8921a7fb2b..9c244b6e1ec3 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf @@ -12,6 +12,11 @@ NETSDK1070: В файле конфигурации приложения должен присутствовать корневой элемент конфигурации. {StrBegin="NETSDK1070: "} + + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + {StrBegin="NETSDK1113: "} + NETSDK1074: The application host executable will not be customized because adding resources requires that the build be performed on Windows (excluding Nano Server). NETSDK1074: исполняемый файл узла приложения не будет настроен, так как для добавления ресурсов требуется, чтобы сборка выполнялась в Windows (за исключением Nano Server). diff --git a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf index 97d90594120a..36a8b574f974 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf @@ -12,6 +12,11 @@ NETSDK1070: Uygulama yapılandırma dosyasının kök yapılandırma öğesi olmalıdır. {StrBegin="NETSDK1070: "} + + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + {StrBegin="NETSDK1113: "} + NETSDK1074: The application host executable will not be customized because adding resources requires that the build be performed on Windows (excluding Nano Server). NETSDK1074: Kaynak eklemek derleme işleminin (Nano Server hariç) Windows'da gerçekleştirilmesini gerektirdiğinden uygulama konağının yürütülebilir dosyası özelleştirilmeyecek. diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf index c733e9b23ee6..764912276737 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf @@ -12,6 +12,11 @@ NETSDK1070: 应用程序配置文件必须具有根配置元素。 {StrBegin="NETSDK1070: "} + + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + {StrBegin="NETSDK1113: "} + NETSDK1074: The application host executable will not be customized because adding resources requires that the build be performed on Windows (excluding Nano Server). NETSDK1074: 未自定义应用程序主机可执行文件,因为添加资源要求在 Windows (不包括 Nano 服务器)上执行生成。 diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf index 969e5ccbb222..8197b471664f 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf @@ -12,6 +12,11 @@ NETSDK1070: 應用程式組態檔必須有根組態元素。 {StrBegin="NETSDK1070: "} + + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + NETSDK1113: Failed to create apphost (attempt {0} out of {1}): {2} + {StrBegin="NETSDK1113: "} + NETSDK1074: The application host executable will not be customized because adding resources requires that the build be performed on Windows (excluding Nano Server). NETSDK1074: 因為正在新增需要在 Windows (不含 Nano 伺服器) 上執行組建的資源,所以該應用程式主機可執行檔無法進行自訂。 diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/CreateAppHost.cs b/src/Tasks/Microsoft.NET.Build.Tasks/CreateAppHost.cs index 981e29ae0be2..a9acda0d1b2e 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/CreateAppHost.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/CreateAppHost.cs @@ -1,10 +1,12 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; +using System.IO; +using System.Threading; using Microsoft.Build.Framework; using Microsoft.NET.HostModel; using Microsoft.NET.HostModel.AppHost; -using System; namespace Microsoft.NET.Build.Tasks { @@ -14,6 +16,11 @@ namespace Microsoft.NET.Build.Tasks /// public class CreateAppHost : TaskBase { + /// + /// The default delay, in milliseconds, for each retry attempt for creating the apphost. + /// + public const int DefaultRetryDelayMilliseconds = 1000; + [Required] public string AppHostSourcePath { get; set; } @@ -28,34 +35,63 @@ public class CreateAppHost : TaskBase public bool WindowsGraphicalUserInterface { get; set; } + public int Retries { get; set; } + + public int RetryDelayMilliseconds { get; set; } = DefaultRetryDelayMilliseconds; + protected override void ExecuteCore() { try { - if (ResourceUpdater.IsSupportedOS()) + var isGUI = WindowsGraphicalUserInterface; + var resourcesAssembly = IntermediateAssembly; + + if (!ResourceUpdater.IsSupportedOS()) { - HostWriter.CreateAppHost(appHostSourceFilePath: AppHostSourcePath, - appHostDestinationFilePath: AppHostDestinationPath, - appBinaryFilePath: AppBinaryName, - windowsGraphicalUserInterface: WindowsGraphicalUserInterface, - assemblyToCopyResorcesFrom: IntermediateAssembly); + if (isGUI) + { + Log.LogWarning(Strings.AppHostCustomizationRequiresWindowsHostWarning); + } + + isGUI = false; + resourcesAssembly = null; } - else + + int attempts = 0; + + do { - // by passing null to assemblyToCopyResorcesFrom, it will skip copying resorces, - // which is only supported on Windows - if (WindowsGraphicalUserInterface) + try { - Log.LogWarning(Strings.AppHostCustomizationRequiresWindowsHostWarning); + HostWriter.CreateAppHost(appHostSourceFilePath: AppHostSourcePath, + appHostDestinationFilePath: AppHostDestinationPath, + appBinaryFilePath: AppBinaryName, + windowsGraphicalUserInterface: isGUI, + assemblyToCopyResorcesFrom: resourcesAssembly); + return; } + catch (Exception ex) when (ex is IOException || + ex is UnauthorizedAccessException) + //ex is ResourceUpdater.HResultException) + { + ++attempts; + + if (Retries < 0 || attempts == Retries) { + throw; + } - HostWriter.CreateAppHost(appHostSourceFilePath: AppHostSourcePath, - appHostDestinationFilePath: AppHostDestinationPath, - appBinaryFilePath: AppBinaryName, - windowsGraphicalUserInterface: false, - assemblyToCopyResorcesFrom: null); + Log.LogWarning( + string.Format(Strings.AppHostCreationFailedWithRetry, + attempts, + Retries, + ex.Message)); + if (RetryDelayMilliseconds > 0) { + Thread.Sleep(RetryDelayMilliseconds); + } + } } + while (attempts < Retries); } catch (AppNameTooLongException ex) { diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets index c46359ba4cf1..ae628291d153 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets @@ -355,12 +355,18 @@ Copyright (c) .NET Foundation. All rights reserved. Exists('$(AppHostSourcePath)')"> <_UseWindowsGraphicalUserInterface Condition="($(RuntimeIdentifier.StartsWith('win')) or $(DefaultAppHostRuntimeIdentifier.StartsWith('win'))) and '$(OutputType)'=='WinExe'">true + 3 + 1000 + + WindowsGraphicalUserInterface="$(_UseWindowsGraphicalUserInterface)" + Retries="$(CreateAppHostRetries)" + RetryDelayMilliseconds="$(CreateAppHostRetryDelay)" + />