Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 45 additions & 12 deletions src/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,6 +57,9 @@ public override SdkResult Resolve(SdkReference sdkReference, SdkResolverContext
{
string msbuildSdksDir = null;
string netcoreSdkVersion = null;
IDictionary<string, string> propertiesToAdd = null;
IDictionary<string, SdkResultItem> itemsToAdd = null;
List<string> warnings = null;

if (context.State is CachedResult priorResult)
{
Expand Down Expand Up @@ -118,6 +122,21 @@ public override SdkResult Resolve(SdkReference sdkReference, SdkResolverContext
netcoreSdkVersion,
minimumVSDefinedSDKVersion);
}

if (resolverResult.FailedToResolveSDKSpecifiedInGlobalJson)
{
if (warnings == null)
{
warnings = new List<string>();
}
warnings.Add(Strings.GlobalJsonResolutionFailed);
if (propertiesToAdd == null)
{
propertiesToAdd = new Dictionary<string, string>();
}
propertiesToAdd.Add("SdkResolverHonoredGlobalJson", "false");
propertiesToAdd.Add("SdkResolverGlobalJsonPath", resolverResult.GlobalJsonPath);
}
}

context.State = new CachedResult
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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),
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Comment thread
sfoslund marked this conversation as resolved.
}
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;
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.DotNet.MSBuildSdkResolver/NETCoreSdkResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public sealed class Result
/// </summary>
public string GlobalJsonPath;

/// <summary>
/// True if a global.json was found but there was no compatible SDK, so it was ignored.
/// </summary>
public bool FailedToResolveSDKSpecifiedInGlobalJson;

public void Initialize(Interop.hostfxr_resolve_sdk2_result_key_t key, string value)
{
switch (key)
Expand Down
3 changes: 3 additions & 0 deletions src/Microsoft.DotNet.MSBuildSdkResolver/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,7 @@
<data name="UnableToLocateNETCoreSdk" xml:space="preserve">
<value>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.</value>
</data>
<data name="GlobalJsonResolutionFailed" xml:space="preserve">
<value>Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</value>
</data>
</root>
5 changes: 5 additions & 0 deletions src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="cs" original="../Strings.resx">
<body>
<trans-unit id="GlobalJsonResolutionFailed">
<source>Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</source>
<target state="new">Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</target>
<note />
</trans-unit>
<trans-unit id="MSBuildSDKDirectoryNotFound">
<source>{0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json.</source>
<target state="needs-review-translation">{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.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="de" original="../Strings.resx">
<body>
<trans-unit id="GlobalJsonResolutionFailed">
<source>Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</source>
<target state="new">Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</target>
<note />
</trans-unit>
<trans-unit id="MSBuildSDKDirectoryNotFound">
<source>{0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json.</source>
<target state="needs-review-translation">{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.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="es" original="../Strings.resx">
<body>
<trans-unit id="GlobalJsonResolutionFailed">
<source>Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</source>
<target state="new">Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</target>
<note />
</trans-unit>
<trans-unit id="MSBuildSDKDirectoryNotFound">
<source>{0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json.</source>
<target state="needs-review-translation">{0} no se encuentra. Compruebe que hay un SDK de .NET Core suficientemente reciente instalado y aumente la versión especificada en global.json.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="fr" original="../Strings.resx">
<body>
<trans-unit id="GlobalJsonResolutionFailed">
<source>Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</source>
<target state="new">Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</target>
<note />
</trans-unit>
<trans-unit id="MSBuildSDKDirectoryNotFound">
<source>{0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json.</source>
<target state="needs-review-translation">{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.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="it" original="../Strings.resx">
<body>
<trans-unit id="GlobalJsonResolutionFailed">
<source>Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</source>
<target state="new">Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</target>
<note />
</trans-unit>
<trans-unit id="MSBuildSDKDirectoryNotFound">
<source>{0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json.</source>
<target state="needs-review-translation">{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.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ja" original="../Strings.resx">
<body>
<trans-unit id="GlobalJsonResolutionFailed">
<source>Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</source>
<target state="new">Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</target>
<note />
</trans-unit>
<trans-unit id="MSBuildSDKDirectoryNotFound">
<source>{0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json.</source>
<target state="needs-review-translation">{0} が見つかりません。十分新しい .NET Core SDK がインストールされていることを確認するか、global.json で指定するバージョンを上げてください (どちらも実行する必要がある場合もあります)。</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ko" original="../Strings.resx">
<body>
<trans-unit id="GlobalJsonResolutionFailed">
<source>Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</source>
<target state="new">Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</target>
<note />
</trans-unit>
<trans-unit id="MSBuildSDKDirectoryNotFound">
<source>{0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json.</source>
<target state="needs-review-translation">{0}을(를) 찾을 수 없습니다. 최신 .NET Core SDK가 설치되어 있는지 확인하거나 global.json에 지정된 버전을 높이세요.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pl" original="../Strings.resx">
<body>
<trans-unit id="GlobalJsonResolutionFailed">
<source>Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</source>
<target state="new">Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</target>
<note />
</trans-unit>
<trans-unit id="MSBuildSDKDirectoryNotFound">
<source>{0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json.</source>
<target state="needs-review-translation">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.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pt-BR" original="../Strings.resx">
<body>
<trans-unit id="GlobalJsonResolutionFailed">
<source>Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</source>
<target state="new">Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</target>
<note />
</trans-unit>
<trans-unit id="MSBuildSDKDirectoryNotFound">
<source>{0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json.</source>
<target state="needs-review-translation">{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.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ru" original="../Strings.resx">
<body>
<trans-unit id="GlobalJsonResolutionFailed">
<source>Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</source>
<target state="new">Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</target>
<note />
</trans-unit>
<trans-unit id="MSBuildSDKDirectoryNotFound">
<source>{0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json.</source>
<target state="needs-review-translation">{0} не найден. Убедитесь, что установлена достаточно свежая версия пакета SDK для .NET Core, и/или увеличьте версию, указанную в файле global.json.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.DotNet.MSBuildSdkResolver/xlf/Strings.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="tr" original="../Strings.resx">
<body>
<trans-unit id="GlobalJsonResolutionFailed">
<source>Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</source>
<target state="new">Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</target>
<note />
</trans-unit>
<trans-unit id="MSBuildSDKDirectoryNotFound">
<source>{0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json.</source>
<target state="needs-review-translation">{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.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="zh-Hans" original="../Strings.resx">
<body>
<trans-unit id="GlobalJsonResolutionFailed">
<source>Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</source>
<target state="new">Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed.</target>
<note />
</trans-unit>
<trans-unit id="MSBuildSDKDirectoryNotFound">
<source>{0} not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json.</source>
<target state="needs-review-translation">{0}未找到。检查是否安装了最新的. net Core SDK,或增加global.json中指定的版本。</target>
Expand Down
Loading