diff --git a/src/NuGet.Clients/NuGet.CommandLine/MsBuildUtility.cs b/src/NuGet.Clients/NuGet.CommandLine/MsBuildUtility.cs index 20b088aed76..3bb4b0764e1 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/MsBuildUtility.cs +++ b/src/NuGet.Clients/NuGet.CommandLine/MsBuildUtility.cs @@ -863,6 +863,17 @@ public static Lazy GetMsBuildDirectoryFromMsBuildPath(string msb throw new CommandException(message); } + if (IsNetCoreMsBuildDirectory(msbuildPath)) + { + var message = string.Format( + CultureInfo.CurrentCulture, + LocalizedResourceManager.GetString( + nameof(NuGetResources.Error_MsBuildIsNetCoreMsBuild)), + msbuildPath); + + throw new CommandException(message); + } + return new Lazy(() => new MsBuildToolset(msbuildVersion, msbuildPath)); } else @@ -871,6 +882,20 @@ public static Lazy GetMsBuildDirectoryFromMsBuildPath(string msb } } + /// + /// Detects whether the given directory contains a .NET SDK (dotnet) MSBuild installation + /// rather than a .NET Framework MSBuild installation. + /// NuGet.exe requires .NET Framework MSBuild because it loads Microsoft.Build.dll + /// in-process via Assembly.LoadFrom, which is incompatible with .NET Core assemblies. + /// Detection uses the presence of MSBuild.runtimeconfig.json, which is the canonical + /// indicator of a .NET Core application and will be present even if a future SDK + /// ships an AoT-compiled MSBuild.exe. + /// + internal static bool IsNetCoreMsBuildDirectory(string msbuildPath) + { + return File.Exists(Path.Combine(msbuildPath, "MSBuild.runtimeconfig.json")); + } + private static void AddProperty(List args, string property, string value) { if (string.IsNullOrEmpty(value)) diff --git a/src/NuGet.Clients/NuGet.CommandLine/NuGetResources.Designer.cs b/src/NuGet.Clients/NuGet.CommandLine/NuGetResources.Designer.cs index 7429fed3318..082dc87a687 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/NuGetResources.Designer.cs +++ b/src/NuGet.Clients/NuGet.CommandLine/NuGetResources.Designer.cs @@ -429,6 +429,15 @@ public static string Error_MissingSourceParameter { } } + /// + /// Looks up a localized string similar to The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild.... + /// + public static string Error_MsBuildIsNetCoreMsBuild { + get { + return ResourceManager.GetString("Error_MsBuildIsNetCoreMsBuild", resourceCulture); + } + } + /// /// Looks up a localized string similar to MSBuild is not installed.. /// diff --git a/src/NuGet.Clients/NuGet.CommandLine/NuGetResources.resx b/src/NuGet.Clients/NuGet.CommandLine/NuGetResources.resx index 3a659370c8b..74a87eb3ebd 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/NuGetResources.resx +++ b/src/NuGet.Clients/NuGet.CommandLine/NuGetResources.resx @@ -736,6 +736,10 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'. The resolved MSBuild directory is `{0}` which is an architecture-specific directory. Could not find MSBuild in its parent directory (non-architecture specific). + + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + {0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'. + '{0} {1}' is deprecated. Use '{0} {2}' instead. {0} - name of the assembly running the command, e.g., NuGet diff --git a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.cs.xlf b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.cs.xlf index 4e9e788fc96..321b7c8482e 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.cs.xlf +++ b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.cs.xlf @@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'. Není zadaný zdrojový parametr. + + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + {0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'. + MsBuild timeout out while trying to get project to project references. Při pokusu o získání odkazů projektu na projekt vypršel časový limit nástroje MsBuild. diff --git a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.de.xlf b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.de.xlf index fbabf62ce1b..4fc79cede20 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.de.xlf +++ b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.de.xlf @@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'. Der Quellparameter wurde nicht angegeben. + + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + {0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'. + MsBuild timeout out while trying to get project to project references. MsBuild-Zeitüberschreitung beim Abrufen von Projekt-zu-Projekt-Verweisen. diff --git a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.es.xlf b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.es.xlf index 6bd374ebb5b..a92259b34fa 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.es.xlf +++ b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.es.xlf @@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'. No se especificó el parámetro de origen. + + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + {0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'. + MsBuild timeout out while trying to get project to project references. Se agotó el tiempo de espera de MsBuild al intentar obtener referencias de proyecto a proyecto. diff --git a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.fr.xlf b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.fr.xlf index ac2595b553d..dd1dc75901d 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.fr.xlf +++ b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.fr.xlf @@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'. Le paramètre source n'a pas été spécifié. + + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + {0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'. + MsBuild timeout out while trying to get project to project references. Expiration du délai de MsBuild lors de la tentative d’obtention des références de projet à projet. diff --git a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.it.xlf b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.it.xlf index f658d797c70..3debf64afb2 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.it.xlf +++ b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.it.xlf @@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'. Il parametro di origine non è stato specificato. + + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + {0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'. + MsBuild timeout out while trying to get project to project references. Timeout di MsBuild durante il tentativo di ottenere i riferimenti da progetto a progetto. diff --git a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.ja.xlf b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.ja.xlf index 7e7580ee36a..79d41dfa0a5 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.ja.xlf +++ b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.ja.xlf @@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'. ソース パラメーターが指定されていませんでした。 + + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + {0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'. + MsBuild timeout out while trying to get project to project references. プロジェクトからプロジェクトへの参照を取得しようとしているときに MSBuild がタイムアウトしました。 diff --git a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.ko.xlf b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.ko.xlf index dc62fdf5e8b..1d2bf5e9fb3 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.ko.xlf +++ b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.ko.xlf @@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'. 원본 매개 변수를 지정하지 않았습니다. + + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + {0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'. + MsBuild timeout out while trying to get project to project references. 프로젝트에서 프로젝트 참조를 가져오는 동안 MsBuild 시간이 초과되었습니다. diff --git a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.pl.xlf b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.pl.xlf index 0aba821132d..54cffe2fadf 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.pl.xlf +++ b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.pl.xlf @@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'. Parametr źródłowy nie został określony. + + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + {0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'. + MsBuild timeout out while trying to get project to project references. Przekroczono limit czasu programu MsBuild podczas próby pobrania odwołań projektu do projektu. diff --git a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.pt-BR.xlf b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.pt-BR.xlf index 187e373822c..28824bfcf25 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.pt-BR.xlf +++ b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.pt-BR.xlf @@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'. O parâmetro de origem não foi especificado. + + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + {0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'. + MsBuild timeout out while trying to get project to project references. O tempo limite do MsBuild foi atingido ao tentar obter referências do projeto para o projeto. diff --git a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.ru.xlf b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.ru.xlf index bf04763eab0..060b1dc0c0c 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.ru.xlf +++ b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.ru.xlf @@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'. Исходный параметр не указан. + + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + {0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'. + MsBuild timeout out while trying to get project to project references. При попытке получить ссылки проекта на проект истекло время ожидания MsBuild. diff --git a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.tr.xlf b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.tr.xlf index a58997c3bc9..b112f7a0c20 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.tr.xlf +++ b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.tr.xlf @@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'. Kaynak parametresi belirtilmedi. + + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + {0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'. + MsBuild timeout out while trying to get project to project references. Proje başvuruları için proje alınmaya çalışılırken MsBuild zaman aşımına uğradı. diff --git a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.zh-Hans.xlf b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.zh-Hans.xlf index fcc4cc35d45..accd9201310 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.zh-Hans.xlf +++ b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.zh-Hans.xlf @@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'. 未指定源参数。 + + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + {0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'. + MsBuild timeout out while trying to get project to project references. 尝试将项目获取到项目引用时,MsBuild 超时。 diff --git a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.zh-Hant.xlf b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.zh-Hant.xlf index 76922ce5952..bcd790a5bbe 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.zh-Hant.xlf +++ b/src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.zh-Hant.xlf @@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'. 未指定來源參數。 + + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + The MSBuild directory '{0}' appears to be a .NET SDK (dotnet) MSBuild installation. NuGet.exe requires the .NET Framework version of MSBuild, which is included with Visual Studio. Use 'dotnet restore' instead, or provide the path to a Visual Studio MSBuild installation. + {0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'. + MsBuild timeout out while trying to get project to project references. 嘗試取得專案參考的專案時,MsBuild 逾時。 diff --git a/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/MSBuildUtilityTest.cs b/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/MSBuildUtilityTest.cs index 3fd3ffd59ab..49331ef43e0 100644 --- a/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/MSBuildUtilityTest.cs +++ b/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/MSBuildUtilityTest.cs @@ -402,6 +402,69 @@ public void CombinePathWithVerboseError_IllegalCharacters_MessageContainsBadPath Assert.Contains(badPath, exception.Message); } + [Fact] + public void IsNetCoreMsBuildDirectory_WithRuntimeConfig_ReturnsTrue() + { + using (var dir = TestDirectory.Create()) + { + File.WriteAllText(Path.Combine(dir, "MSBuild.runtimeconfig.json"), "{}"); + + Assert.True(MsBuildUtility.IsNetCoreMsBuildDirectory(dir)); + } + } + + [Fact] + public void IsNetCoreMsBuildDirectory_WithRuntimeConfigAndMsBuildExe_ReturnsTrue() + { + // Even if a future AoT SDK ships MSBuild.exe, the runtimeconfig.json + // still marks it as .NET Core, and NuGet.exe cannot load its assemblies. + using (var dir = TestDirectory.Create()) + { + File.WriteAllText(Path.Combine(dir, "MSBuild.exe"), "fake"); + File.WriteAllText(Path.Combine(dir, "MSBuild.runtimeconfig.json"), "{}"); + + Assert.True(MsBuildUtility.IsNetCoreMsBuildDirectory(dir)); + } + } + + [Fact] + public void IsNetCoreMsBuildDirectory_WithMsBuildExeOnly_ReturnsFalse() + { + using (var dir = TestDirectory.Create()) + { + File.WriteAllText(Path.Combine(dir, "MSBuild.exe"), "fake"); + + Assert.False(MsBuildUtility.IsNetCoreMsBuildDirectory(dir)); + } + } + + [Fact] + public void IsNetCoreMsBuildDirectory_EmptyDirectory_ReturnsFalse() + { + using (var dir = TestDirectory.Create()) + { + Assert.False(MsBuildUtility.IsNetCoreMsBuildDirectory(dir)); + } + } + + [Fact] + public void GetMsBuildDirectoryFromMsBuildPath_NetCoreMsBuild_ThrowsCommandException() + { + using (var dir = TestDirectory.Create()) + { + File.WriteAllText(Path.Combine(dir, "MSBuild.runtimeconfig.json"), "{}"); + + CommandException exception = Assert.Throws( + () => MsBuildUtility.GetMsBuildDirectoryFromMsBuildPath(dir, null, null)); + + string expectedMessage = string.Format( + CultureInfo.CurrentCulture, + LocalizedResourceManager.GetString(nameof(NuGetResources.Error_MsBuildIsNetCoreMsBuild)), + dir.ToString()); + Assert.Equal(expectedMessage, exception.Message); + } + } + public static class ToolsetDataSource { // Legacy toolsets