diff --git a/src/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs b/src/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs index d3839e5d8ee9..1bbc4b3bc461 100644 --- a/src/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs +++ b/src/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs @@ -4,6 +4,7 @@ using Microsoft.Build.Framework; using System; using System.Collections.Concurrent; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; @@ -56,6 +57,9 @@ public override SdkResult Resolve(SdkReference sdkReference, SdkResolverContext { string msbuildSdksDir = null; string netcoreSdkVersion = null; + IDictionary propertiesToAdd = null; + IDictionary itemsToAdd = null; + List warnings = null; if (context.State is CachedResult priorResult) { @@ -118,6 +122,21 @@ public override SdkResult Resolve(SdkReference sdkReference, SdkResolverContext netcoreSdkVersion, minimumVSDefinedSDKVersion); } + + if (resolverResult.FailedToResolveSDKSpecifiedInGlobalJson) + { + if (warnings == null) + { + warnings = new List(); + } + warnings.Add(Strings.GlobalJsonResolutionFailed); + if (propertiesToAdd == null) + { + propertiesToAdd = new Dictionary(); + } + propertiesToAdd.Add("SdkResolverHonoredGlobalJson", "false"); + propertiesToAdd.Add("SdkResolverGlobalJsonPath", resolverResult.GlobalJsonPath); + } } context.State = new CachedResult @@ -135,7 +154,7 @@ public override SdkResult Resolve(SdkReference sdkReference, SdkResolverContext msbuildSdkDir); } - return factory.IndicateSuccess(msbuildSdkDir, netcoreSdkVersion); + return factory.IndicateSuccess(msbuildSdkDir, netcoreSdkVersion, propertiesToAdd, itemsToAdd, warnings); } private static SdkResult Failure(SdkResultFactory factory, string format, params object[] args) @@ -186,9 +205,9 @@ public CompatibleSdkValue(string mostRecentCompatible, string mostRecentCompatib } } - private string GetMostCompatibleSdk(string dotnetExeDirectory, Version msbuildVersion) + private string GetMostCompatibleSdk(string dotnetExeDirectory, Version msbuildVersion, int minimumSdkMajorVersion = 0) { - CompatibleSdkValue sdks = GetMostCompatibleSdks(dotnetExeDirectory, msbuildVersion); + CompatibleSdkValue sdks = GetMostCompatibleSdks(dotnetExeDirectory, msbuildVersion, minimumSdkMajorVersion); if (_vsSettings.DisallowPrerelease()) { return sdks.MostRecentCompatibleNonPreview; @@ -197,7 +216,7 @@ private string GetMostCompatibleSdk(string dotnetExeDirectory, Version msbuildVe return sdks.MostRecentCompatible; } - private CompatibleSdkValue GetMostCompatibleSdks(string dotnetExeDirectory, Version msbuildVersion) + private CompatibleSdkValue GetMostCompatibleSdks(string dotnetExeDirectory, Version msbuildVersion, int minimumSdkMajorVersion) { return s_compatibleSdks.GetOrAdd( new CompatibleSdkKey(dotnetExeDirectory, msbuildVersion), @@ -218,6 +237,11 @@ private CompatibleSdkValue GetMostCompatibleSdks(string dotnetExeDirectory, Vers continue; } + if (minimumSdkMajorVersion != 0 && Int32.TryParse(netcoreSdkVersion.Split('.')[0], out int sdkMajorVersion) && sdkMajorVersion < minimumSdkMajorVersion) + { + continue; + } + if (mostRecent == null) { mostRecent = netcoreSdkDir; @@ -293,16 +317,25 @@ private NETCoreSdkResolver.Result ResolveNETCoreSdkDirectory(SdkResolverContext string globalJsonStartDir = Path.GetDirectoryName(context.SolutionFilePath ?? context.ProjectFilePath); var result = NETCoreSdkResolver.ResolveSdk(dotnetExeDir, globalJsonStartDir, _vsSettings.DisallowPrerelease()); - if (result.ResolvedSdkDirectory != null - && result.GlobalJsonPath == null - && context.MSBuildVersion < GetMinimumMSBuildVersion(result.ResolvedSdkDirectory)) + string mostCompatible = result.ResolvedSdkDirectory; + if (result.ResolvedSdkDirectory == null + && result.GlobalJsonPath != null + && context.IsRunningInVisualStudio) + { + result.FailedToResolveSDKSpecifiedInGlobalJson = true; + // We need the SDK to be version 5 or higher to ensure that we generate a build error when we fail to resolve the SDK specified by global.json + mostCompatible = GetMostCompatibleSdk(dotnetExeDir, context.MSBuildVersion, 5); + } + else if (result.ResolvedSdkDirectory != null + && result.GlobalJsonPath == null + && context.MSBuildVersion < GetMinimumMSBuildVersion(result.ResolvedSdkDirectory)) { - string mostCompatible = GetMostCompatibleSdk(dotnetExeDir, context.MSBuildVersion); + mostCompatible = GetMostCompatibleSdk(dotnetExeDir, context.MSBuildVersion); + } - if (mostCompatible != null) - { - result.ResolvedSdkDirectory = mostCompatible; - } + if (mostCompatible != null) + { + result.ResolvedSdkDirectory = mostCompatible; } return result; diff --git a/src/Microsoft.DotNet.MSBuildSdkResolver/NETCoreSdkResolver.cs b/src/Microsoft.DotNet.MSBuildSdkResolver/NETCoreSdkResolver.cs index e00c618d93d7..d5f29e65d8ef 100644 --- a/src/Microsoft.DotNet.MSBuildSdkResolver/NETCoreSdkResolver.cs +++ b/src/Microsoft.DotNet.MSBuildSdkResolver/NETCoreSdkResolver.cs @@ -20,6 +20,11 @@ public sealed class Result /// public string GlobalJsonPath; + /// + /// True if a global.json was found but there was no compatible SDK, so it was ignored. + /// + public bool FailedToResolveSDKSpecifiedInGlobalJson; + public void Initialize(Interop.hostfxr_resolve_sdk2_result_key_t key, string value) { switch (key) diff --git a/src/Microsoft.DotNet.MSBuildSdkResolver/Strings.resx b/src/Microsoft.DotNet.MSBuildSdkResolver/Strings.resx index 548e00f32fe4..0b839942726e 100644 --- a/src/Microsoft.DotNet.MSBuildSdkResolver/Strings.resx +++ b/src/Microsoft.DotNet.MSBuildSdkResolver/Strings.resx @@ -132,4 +132,7 @@ Unable to locate the .NET SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version. + + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + diff --git a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.cs.xlf b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.cs.xlf index 5842cba7e801..5876e58289b0 100644 --- a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.cs.xlf +++ b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.cs.xlf @@ -2,6 +2,11 @@ + + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + + {0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json. {0} nejde najít. Zajistěte, aby byla nainstalovaná dostatečně vysoká verze sady .NET Core SDK, a/nebo zvyšte verzi zadanou v souboru global.json. diff --git a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.de.xlf b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.de.xlf index 37f896733aff..e29a5661ce57 100644 --- a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.de.xlf +++ b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.de.xlf @@ -2,6 +2,11 @@ + + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + + {0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json. {0} wurde nicht gefunden. Stellen Sie sicher, dass eine aktuelle Version des .NET Core SDK installiert ist, und/oder erhöhen Sie die in "global.json" angegebene Version. diff --git a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.es.xlf b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.es.xlf index 6837dba032da..86544e3942ff 100644 --- a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.es.xlf +++ b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.es.xlf @@ -2,6 +2,11 @@ + + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + + {0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json. {0} no se encuentra. Compruebe que hay un SDK de .NET Core suficientemente reciente instalado y aumente la versión especificada en global.json. diff --git a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.fr.xlf b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.fr.xlf index 9904f66cf67a..0cfd8a53cc98 100644 --- a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.fr.xlf +++ b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.fr.xlf @@ -2,6 +2,11 @@ + + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + + {0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json. {0} introuvable. Vérifiez qu'un SDK .NET Core suffisamment récent est installé et/ou augmentez la version spécifiée dans global.json. diff --git a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.it.xlf b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.it.xlf index cbd23fe4fdc5..dc0aa94c66ca 100644 --- a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.it.xlf +++ b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.it.xlf @@ -2,6 +2,11 @@ + + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + + {0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json. {0} non è stato trovato. Verificare che sia installata una versione abbastanza recente di .NET Core SDK e/o aumentare la versione specificata in global.json. diff --git a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.ja.xlf b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.ja.xlf index edae0d5ce511..ded3baf852fc 100644 --- a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.ja.xlf +++ b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.ja.xlf @@ -2,6 +2,11 @@ + + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + + {0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json. {0} が見つかりません。十分新しい .NET Core SDK がインストールされていることを確認するか、global.json で指定するバージョンを上げてください (どちらも実行する必要がある場合もあります)。 diff --git a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.ko.xlf b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.ko.xlf index 7a3641d8e1c1..b2c9cdc28922 100644 --- a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.ko.xlf +++ b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.ko.xlf @@ -2,6 +2,11 @@ + + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + + {0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json. {0}을(를) 찾을 수 없습니다. 최신 .NET Core SDK가 설치되어 있는지 확인하거나 global.json에 지정된 버전을 높이세요. diff --git a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.pl.xlf b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.pl.xlf index d6a417a96853..b4ec17d6d84e 100644 --- a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.pl.xlf +++ b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.pl.xlf @@ -2,6 +2,11 @@ + + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + + {0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json. Nie można odnaleźć elementu {0}. Sprawdź, czy zainstalowano wystarczająco aktualną wersję zestawu .NET Core SDK i/lub zwiększ wersję określoną w pliku global.json. diff --git a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.pt-BR.xlf b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.pt-BR.xlf index 8857826ccc8c..2520a52b19b9 100644 --- a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.pt-BR.xlf +++ b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.pt-BR.xlf @@ -2,6 +2,11 @@ + + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + + {0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json. {0} não encontrado. Verifique se um SDK do .NET Core suficientemente recente está instalado e/ou aumente a versão especificada no global.json. diff --git a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.ru.xlf b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.ru.xlf index eba0fd0cb460..eecabe0067e3 100644 --- a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.ru.xlf +++ b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.ru.xlf @@ -2,6 +2,11 @@ + + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + + {0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json. {0} не найден. Убедитесь, что установлена достаточно свежая версия пакета SDK для .NET Core, и/или увеличьте версию, указанную в файле global.json. diff --git a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.tr.xlf b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.tr.xlf index e15cdc3eb74d..fd0051aff00c 100644 --- a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.tr.xlf +++ b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.tr.xlf @@ -2,6 +2,11 @@ + + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + + {0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json. {0} bulunamadı. Yeterince yeni bir .NET Core SDK'sının yüklü olduğundan emin olun ve/veya global.json içinde belirtilen sürümü artırın. diff --git a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.zh-Hans.xlf b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.zh-Hans.xlf index 178e865d544a..19bcc81d5acc 100644 --- a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.zh-Hans.xlf +++ b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.zh-Hans.xlf @@ -2,6 +2,11 @@ + + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + + {0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json. {0}未找到。检查是否安装了最新的. net Core SDK,或增加global.json中指定的版本。 diff --git a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.zh-Hant.xlf b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.zh-Hant.xlf index 1e56c9476536..7b789f83c55f 100644 --- a/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.zh-Hant.xlf +++ b/src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.zh-Hant.xlf @@ -2,6 +2,11 @@ + + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed. + + {0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json. 找不到 {0}。請檢查安裝版本的 .NET Core SDK 是否夠新,並 (或) 提高 global.json 中指定的版本。 diff --git a/src/Tasks/Common/Resources/Strings.resx b/src/Tasks/Common/Resources/Strings.resx index 243affd6b99c..51cb7bce3197 100644 --- a/src/Tasks/Common/Resources/Strings.resx +++ b/src/Tasks/Common/Resources/Strings.resx @@ -666,4 +666,8 @@ The following are names of parameters or literal values and should not be transl {2} {StrBegin="NETSDK1140: "} + + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + {StrBegin="NETSDK1141: "} + diff --git a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf index 96834b6e0b5e..bf74b6d58c5f 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf @@ -349,6 +349,11 @@ NETSDK1049: Přeložený soubor má nesprávnou image, nemá žádná metadata nebo je jiným způsobem nedostupný. {0} {1} {StrBegin="NETSDK1049: "} + + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + {StrBegin="NETSDK1141: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: Pro vybranou konfiguraci publikování se optimalizace velikosti sestavení nepodporuje. Ujistěte se, že publikujete samostatnou aplikaci. diff --git a/src/Tasks/Common/Resources/xlf/Strings.de.xlf b/src/Tasks/Common/Resources/xlf/Strings.de.xlf index 76d45c6794f7..02fe467874de 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.de.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.de.xlf @@ -349,6 +349,11 @@ NETSDK1049: Die aufgelöste Datei enthält ein fehlerhaftes Image oder keine Metadaten, oder der Zugriff ist aus anderen Gründen nicht möglich. {0} {1} {StrBegin="NETSDK1049: "} + + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + {StrBegin="NETSDK1141: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: Die Größenoptimierung von Assemblys wird für die ausgewählte Veröffentlichungskonfiguration nicht unterstützt. Stellen Sie sicher, dass Sie eine eigenständige App veröffentlichen. diff --git a/src/Tasks/Common/Resources/xlf/Strings.es.xlf b/src/Tasks/Common/Resources/xlf/Strings.es.xlf index 5f446f198a9d..86d54e01bf1e 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.es.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.es.xlf @@ -349,6 +349,11 @@ NETSDK1049: El archivo resuelto tiene una imagen incorrecta, no tiene metadatos o no es posible su acceso. {0} {1} {StrBegin="NETSDK1049: "} + + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + {StrBegin="NETSDK1141: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: No se admite la optimización de tamaño de los ensamblados para la configuración de publicación seleccionada. Asegúrese de que está publicando una aplicación autónoma. diff --git a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf index abfe30684aac..ecb9a0d4e5d2 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf @@ -349,6 +349,11 @@ NETSDK1049: Le fichier résolu a une image incorrecte, ne comporte pas de métadonnées ou n'est pas accessible. {0} {1} {StrBegin="NETSDK1049: "} + + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + {StrBegin="NETSDK1141: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: l'optimisation de la taille des assemblys n'est pas prise en charge pour la configuration de publication sélectionnée. Vérifiez que vous publiez une application autonome. diff --git a/src/Tasks/Common/Resources/xlf/Strings.it.xlf b/src/Tasks/Common/Resources/xlf/Strings.it.xlf index 403c821ff3da..b60f243b334d 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.it.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.it.xlf @@ -349,6 +349,11 @@ NETSDK1049: il file risolto ha un'immagine danneggiata, non contiene metadati o è inaccessibile per altri motivi. {0} {1} {StrBegin="NETSDK1049: "} + + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + {StrBegin="NETSDK1141: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: l'ottimizzazione degli assembly per le dimensioni non è supportata per la configurazione di pubblicazione selezionata. Assicurarsi di pubblicare un'app indipendente. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf index 391582ebb82f..c07ad4b34909 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf @@ -349,6 +349,11 @@ NETSDK1049: 解決されたファイルは、無効なイメージが含まれているか、メタデータが存在しないか、またはアクセスできません。{0} {1} {StrBegin="NETSDK1049: "} + + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + {StrBegin="NETSDK1141: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: アセンブリのサイズの最適化は、選択された公開構成に対してはサポートされていません。自己完結型のアプリを公開していることをご確認ください。 diff --git a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf index 0987fd3811fc..5649ff24aa6b 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf @@ -349,6 +349,11 @@ NETSDK1049: 확인된 파일의 이미지가 잘못되었거나, 메타데이터가 없거나, 파일 자체에 액세스할 수 없습니다. {0} {1} {StrBegin="NETSDK1049: "} + + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + {StrBegin="NETSDK1141: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: 선택한 게시 구성에서는 크기에 대한 어셈블리 최적화가 지원되지 않습니다. 자체 포함 앱을 게시하고 있는지 확인하세요. diff --git a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf index de91e7c8ce1f..4ccece6c37c7 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf @@ -349,6 +349,11 @@ NETSDK1049: Rozpoznany plik ma nieprawidłowy obraz, nie ma metadanych lub jest w inny sposób niedostępny. {0} {1} {StrBegin="NETSDK1049: "} + + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + {StrBegin="NETSDK1141: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: Optymalizacja zestawów pod kątem rozmiaru nie jest obsługiwana w przypadku wybranej konfiguracji publikowania. Upewnij się, że publikujesz niezależną aplikację. diff --git a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf index 77df417cb9b1..bf428ef93faa 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf @@ -349,6 +349,11 @@ NETSDK1049: O arquivo resolvido tem uma imagem inválida, não tem metadados ou está inacessível. {0} {1} {StrBegin="NETSDK1049: "} + + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + {StrBegin="NETSDK1141: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: não há suporte para a otimização de assemblies para tamanho na configuração de publicação selecionada. Verifique se você está publicando um aplicativo independente. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf index 76960df4c2b2..3fa36637a2cc 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf @@ -349,6 +349,11 @@ NETSDK1049: разрешенный файл содержит недопустимый образ, не содержит метаданных или недоступен по другим причинам. {0} {1} {StrBegin="NETSDK1049: "} + + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + {StrBegin="NETSDK1141: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: оптимизация сборок по размеру не поддерживается для выбранной конфигурации публикации. Убедитесь, что вы публикуете автономное приложение. diff --git a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf index 2140dca1cd1f..0c8edccbbc7d 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf @@ -349,6 +349,11 @@ NETSDK1049: Çözümlenen dosyada hatalı görüntü var, meta veri yok veya dosya erişilemez durumda. {0} {1} {StrBegin="NETSDK1049: "} + + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + {StrBegin="NETSDK1141: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: Derlemeleri boyut için iyileştirme, seçilen yayımlama yapılandırması için desteklenmiyor. Lütfen kendi içinde bulunan bir uygulama yayımladığınızdan emin olun. diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf index 839ee924011a..b2e0ee1449c3 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf @@ -349,6 +349,11 @@ NETSDK1049: 解析的文件包含错误图像、无元数据或不可访问。{0} {1} {StrBegin="NETSDK1049: "} + + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + {StrBegin="NETSDK1141: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: 所选发布配置不支持优化程序集的大小。请确保你发布的是独立应用。 diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf index 9f3c6af658e3..0e663f6b602d 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf @@ -349,6 +349,11 @@ NETSDK1049: 解析的檔案含有毀損的映像、沒有中繼資料,或有其他無法存取的情況。{0} {1} {StrBegin="NETSDK1049: "} + + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at {0}. + {StrBegin="NETSDK1141: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: 選取的發佈設定不支援最佳化組件的大小。請確定您發佈的是獨立式應用程式。 diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.DefaultItems.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.DefaultItems.targets index 2f35e84f780c..075f576ac10d 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.DefaultItems.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.DefaultItems.targets @@ -343,6 +343,13 @@ Copyright (c) .NET Foundation. All rights reserved. + + + + diff --git a/src/Tests/Microsoft.DotNet.MSBuildSdkResolver.Tests/GivenAnMSBuildSdkResolver.cs b/src/Tests/Microsoft.DotNet.MSBuildSdkResolver.Tests/GivenAnMSBuildSdkResolver.cs index 79b017c7a4f2..2561cbfc56d5 100644 --- a/src/Tests/Microsoft.DotNet.MSBuildSdkResolver.Tests/GivenAnMSBuildSdkResolver.cs +++ b/src/Tests/Microsoft.DotNet.MSBuildSdkResolver.Tests/GivenAnMSBuildSdkResolver.cs @@ -156,6 +156,7 @@ public void ItReturnsHighestSdkAvailableThatIsCompatibleWithMSBuild(bool disallo result.Success.Should().BeTrue(); result.Path.Should().Be((disallowPreviews ? compatibleRtm : compatiblePreview).FullName); result.AdditionalPaths.Should().BeNull(); + result.PropertiesToAdd.Should().BeNull(); result.Version.Should().Be(disallowPreviews ? "98.98.98" : "99.99.99-preview"); result.Warnings.Should().BeNullOrEmpty(); result.Errors.Should().BeNullOrEmpty(); @@ -164,7 +165,7 @@ public void ItReturnsHighestSdkAvailableThatIsCompatibleWithMSBuild(bool disallo [Theory] [InlineData(true)] [InlineData(false)] - public void ItDoesNotReturnHighestSdkAvailableThatIsCompatibleWithMSBuildWhenVersionInGlobalJsonCannotBeFound(bool disallowPreviews) + public void ItDoesNotReturnHighestSdkAvailableThatIsCompatibleWithMSBuildWhenVersionInGlobalJsonCannotBeFoundOutsideOfVisualStudio(bool disallowPreviews) { var environment = new TestEnvironment(_testAssetsManager, callingMethod: "ItDoesNotReturnHighest___", identifier: disallowPreviews.ToString()) { @@ -185,17 +186,59 @@ public void ItDoesNotReturnHighestSdkAvailableThatIsCompatibleWithMSBuildWhenVer { MSBuildVersion = new Version(20, 0, 0, 0), ProjectFileDirectory = environment.TestDirectory, + IsRunningInVisualStudio = false }, new MockFactory()); result.Success.Should().BeFalse(); result.Path.Should().BeNull(); result.AdditionalPaths.Should().BeNull(); - result.Version.Should().BeNull();; + result.PropertiesToAdd.Should().BeNull(); + result.Version.Should().BeNull(); result.Warnings.Should().BeNullOrEmpty(); result.Errors.Should().NotBeEmpty(); } + [Theory] + [InlineData(true)] + [InlineData(false)] + public void ItReturnsHighestSdkAvailableThatIsCompatibleWithMSBuildWhenVersionInGlobalJsonCannotBeFoundAndRunningInVisualStudio(bool disallowPreviews) + { + var environment = new TestEnvironment(_testAssetsManager, callingMethod: "ItReturnsHighest___", identifier: disallowPreviews.ToString()) + { + DisallowPrereleaseByDefault = disallowPreviews + }; + + var compatibleRtm = environment.CreateSdkDirectory(ProgramFiles.X64, "Some.Test.Sdk", "98.98.98", new Version(19, 0, 0, 0)); + var compatiblePreview = environment.CreateSdkDirectory(ProgramFiles.X64, "Some.Test.Sdk", "99.99.99-preview", new Version(20, 0, 0, 0)); + var incompatible = environment.CreateSdkDirectory(ProgramFiles.X64, "Some.Test.Sdk", "100.100.100", new Version(21, 0, 0, 0)); + + environment.CreateMuxerAndAddToPath(ProgramFiles.X64); + environment.CreateGlobalJson(environment.TestDirectory, "1.2.3"); + + var resolver = environment.CreateResolver(); + var result = (MockResult)resolver.Resolve( + new SdkReference("Some.Test.Sdk", null, null), + new MockContext + { + MSBuildVersion = new Version(20, 0, 0, 0), + ProjectFileDirectory = environment.TestDirectory, + IsRunningInVisualStudio = true + }, + new MockFactory()); + + result.Success.Should().BeTrue(); + result.Path.Should().Be((disallowPreviews ? compatibleRtm : compatiblePreview).FullName); + result.AdditionalPaths.Should().BeNull(); + result.PropertiesToAdd.Count.Should().Be(2); + result.PropertiesToAdd.ContainsKey("SdkResolverHonoredGlobalJson"); + result.PropertiesToAdd.ContainsKey("SdkResolverGlobalJsonPath"); + result.PropertiesToAdd["SdkResolverHonoredGlobalJson"].Should().Be("false"); + result.Version.Should().Be(disallowPreviews ? "98.98.98" : "99.99.99-preview"); + result.Warnings.Should().BeEquivalentTo(new[] { "Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed." }); + result.Errors.Should().BeNullOrEmpty(); + } + [Fact] public void ItReturnsNullWhenTheDefaultVSRequiredSDKVersionIsHigherThanTheSDKVersionAvailable() { @@ -609,6 +652,7 @@ private sealed class MockContext : SdkResolverContext public new string ProjectFilePath { get => base.ProjectFilePath; set => base.ProjectFilePath = value; } public new string SolutionFilePath { get => base.SolutionFilePath; set => base.SolutionFilePath = value; } public new Version MSBuildVersion { get => base.MSBuildVersion; set => base.MSBuildVersion = value; } + public new bool IsRunningInVisualStudio { get => base.IsRunningInVisualStudio; set => base.IsRunningInVisualStudio = value; } public DirectoryInfo ProjectFileDirectory { @@ -630,6 +674,9 @@ public override SdkResult IndicateFailure(IEnumerable errors, IEnumerabl public override SdkResult IndicateSuccess(string path, string version, IEnumerable warnings = null) => new MockResult(success: true, path: path, version: version, warnings: warnings); + public override SdkResult IndicateSuccess(string path, string version, IDictionary propertiesToAdd, IDictionary itemsToAdd, IEnumerable warnings = null) + => new MockResult(success: true, path: path, version: version, warnings: warnings, propertiesToAdd: propertiesToAdd, itemsToAdd: itemsToAdd); + public override SdkResult IndicateSuccess(IEnumerable paths, string version, IDictionary propertiesToAdd = null, IDictionary itemsToAdd = null, IEnumerable warnings = null) => new MockResult(success: true, paths: paths, version: version, propertiesToAdd, itemsToAdd, warnings); @@ -638,13 +685,15 @@ public override SdkResult IndicateSuccess(IEnumerable paths, string vers private sealed class MockResult : SdkResult { public MockResult(bool success, string path, string version, IEnumerable warnings = null, - IEnumerable errors = null) + IEnumerable errors = null, IDictionary propertiesToAdd = null, IDictionary itemsToAdd = null) { Success = success; Path = path; Version = version; Warnings = warnings; Errors = errors; + PropertiesToAdd = propertiesToAdd; + ItemsToAdd = itemsToAdd; } public MockResult(bool success, IEnumerable paths, string version, diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildWithGlobalJson.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildWithGlobalJson.cs new file mode 100644 index 000000000000..b1113b248b58 --- /dev/null +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildWithGlobalJson.cs @@ -0,0 +1,44 @@ +// 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 FluentAssertions; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Xunit; +using Xunit.Abstractions; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.ProjectConstruction; + +namespace Microsoft.NET.Build.Tests +{ + public class GivenThatWeWantToBuildWithGlobalJson : SdkTest + { + public GivenThatWeWantToBuildWithGlobalJson(ITestOutputHelper log) : base(log) + {} + + [Fact] + public void It_fails_build_on_failed_sdk_resolution() + { + var fakePath = "fakePath"; + TestProject testProject = new TestProject() + { + Name = "FailedResolution", + IsSdkProject = true, + TargetFrameworks = "net5.0" + }; + testProject.AdditionalProperties["SdkResolverHonoredGlobalJson"] = "false"; + testProject.AdditionalProperties["SdkResolverGlobalJsonPath"] = fakePath; + + var testAsset = _testAssetsManager.CreateTestProject(testProject); + + var buildCommand = new BuildCommand(testAsset); + buildCommand.Execute() + .Should() + .Fail() + .And + .HaveStdOutContaining("NETSDK1141") + .And + .HaveStdOutContaining(fakePath); + } + } +}