Skip to content

Commit 461fa93

Browse files
authored
Warn that NuGet.exe needs .NET Framework MSBuild (#7261)
1 parent 106309a commit 461fa93

17 files changed

Lines changed: 166 additions & 0 deletions

src/NuGet.Clients/NuGet.CommandLine/MsBuildUtility.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,17 @@ public static Lazy<MsBuildToolset> GetMsBuildDirectoryFromMsBuildPath(string msb
863863
throw new CommandException(message);
864864
}
865865

866+
if (IsNetCoreMsBuildDirectory(msbuildPath))
867+
{
868+
var message = string.Format(
869+
CultureInfo.CurrentCulture,
870+
LocalizedResourceManager.GetString(
871+
nameof(NuGetResources.Error_MsBuildIsNetCoreMsBuild)),
872+
msbuildPath);
873+
874+
throw new CommandException(message);
875+
}
876+
866877
return new Lazy<MsBuildToolset>(() => new MsBuildToolset(msbuildVersion, msbuildPath));
867878
}
868879
else
@@ -871,6 +882,20 @@ public static Lazy<MsBuildToolset> GetMsBuildDirectoryFromMsBuildPath(string msb
871882
}
872883
}
873884

885+
/// <summary>
886+
/// Detects whether the given directory contains a .NET SDK (dotnet) MSBuild installation
887+
/// rather than a .NET Framework MSBuild installation.
888+
/// NuGet.exe requires .NET Framework MSBuild because it loads Microsoft.Build.dll
889+
/// in-process via Assembly.LoadFrom, which is incompatible with .NET Core assemblies.
890+
/// Detection uses the presence of MSBuild.runtimeconfig.json, which is the canonical
891+
/// indicator of a .NET Core application and will be present even if a future SDK
892+
/// ships an AoT-compiled MSBuild.exe.
893+
/// </summary>
894+
internal static bool IsNetCoreMsBuildDirectory(string msbuildPath)
895+
{
896+
return File.Exists(Path.Combine(msbuildPath, "MSBuild.runtimeconfig.json"));
897+
}
898+
874899
private static void AddProperty(List<string> args, string property, string value)
875900
{
876901
if (string.IsNullOrEmpty(value))

src/NuGet.Clients/NuGet.CommandLine/NuGetResources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/NuGet.Clients/NuGet.CommandLine/NuGetResources.resx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,10 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'.</comment>
736736
<data name="Error_CannotFindNonArchitectureSpecificMsbuild" xml:space="preserve">
737737
<value>The resolved MSBuild directory is `{0}` which is an architecture-specific directory. Could not find MSBuild in its parent directory (non-architecture specific).</value>
738738
</data>
739+
<data name="Error_MsBuildIsNetCoreMsBuild" xml:space="preserve">
740+
<value>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.</value>
741+
<comment>{0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'.</comment>
742+
</data>
739743
<data name="Warning_CommandDeprecated" xml:space="preserve">
740744
<value>'{0} {1}' is deprecated. Use '{0} {2}' instead.</value>
741745
<comment>{0} - name of the assembly running the command, e.g., NuGet

src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.cs.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'.</note>
213213
<target state="translated">Není zadaný zdrojový parametr.</target>
214214
<note />
215215
</trans-unit>
216+
<trans-unit id="Error_MsBuildIsNetCoreMsBuild">
217+
<source>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.</source>
218+
<target state="new">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.</target>
219+
<note>{0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'.</note>
220+
</trans-unit>
216221
<trans-unit id="Error_MsBuildTimedOut">
217222
<source>MsBuild timeout out while trying to get project to project references.</source>
218223
<target state="translated">Při pokusu o získání odkazů projektu na projekt vypršel časový limit nástroje MsBuild.</target>

src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.de.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'.</note>
213213
<target state="translated">Der Quellparameter wurde nicht angegeben.</target>
214214
<note />
215215
</trans-unit>
216+
<trans-unit id="Error_MsBuildIsNetCoreMsBuild">
217+
<source>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.</source>
218+
<target state="new">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.</target>
219+
<note>{0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'.</note>
220+
</trans-unit>
216221
<trans-unit id="Error_MsBuildTimedOut">
217222
<source>MsBuild timeout out while trying to get project to project references.</source>
218223
<target state="translated">MsBuild-Zeitüberschreitung beim Abrufen von Projekt-zu-Projekt-Verweisen.</target>

src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.es.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'.</note>
213213
<target state="translated">No se especificó el parámetro de origen.</target>
214214
<note />
215215
</trans-unit>
216+
<trans-unit id="Error_MsBuildIsNetCoreMsBuild">
217+
<source>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.</source>
218+
<target state="new">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.</target>
219+
<note>{0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'.</note>
220+
</trans-unit>
216221
<trans-unit id="Error_MsBuildTimedOut">
217222
<source>MsBuild timeout out while trying to get project to project references.</source>
218223
<target state="translated">Se agotó el tiempo de espera de MsBuild al intentar obtener referencias de proyecto a proyecto.</target>

src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.fr.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'.</note>
213213
<target state="translated">Le paramètre source n'a pas été spécifié.</target>
214214
<note />
215215
</trans-unit>
216+
<trans-unit id="Error_MsBuildIsNetCoreMsBuild">
217+
<source>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.</source>
218+
<target state="new">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.</target>
219+
<note>{0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'.</note>
220+
</trans-unit>
216221
<trans-unit id="Error_MsBuildTimedOut">
217222
<source>MsBuild timeout out while trying to get project to project references.</source>
218223
<target state="translated">Expiration du délai de MsBuild lors de la tentative d’obtention des références de projet à projet.</target>

src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.it.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'.</note>
213213
<target state="translated">Il parametro di origine non è stato specificato.</target>
214214
<note />
215215
</trans-unit>
216+
<trans-unit id="Error_MsBuildIsNetCoreMsBuild">
217+
<source>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.</source>
218+
<target state="new">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.</target>
219+
<note>{0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'.</note>
220+
</trans-unit>
216221
<trans-unit id="Error_MsBuildTimedOut">
217222
<source>MsBuild timeout out while trying to get project to project references.</source>
218223
<target state="translated">Timeout di MsBuild durante il tentativo di ottenere i riferimenti da progetto a progetto.</target>

src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.ja.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'.</note>
213213
<target state="translated">ソース パラメーターが指定されていませんでした。</target>
214214
<note />
215215
</trans-unit>
216+
<trans-unit id="Error_MsBuildIsNetCoreMsBuild">
217+
<source>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.</source>
218+
<target state="new">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.</target>
219+
<note>{0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'.</note>
220+
</trans-unit>
216221
<trans-unit id="Error_MsBuildTimedOut">
217222
<source>MsBuild timeout out while trying to get project to project references.</source>
218223
<target state="translated">プロジェクトからプロジェクトへの参照を取得しようとしているときに MSBuild がタイムアウトしました。</target>

src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetResources.ko.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ Do not localize `SDK`, `dotnet pack`, msbuild -t:pack` and 'true'.</note>
213213
<target state="translated">원본 매개 변수를 지정하지 않았습니다.</target>
214214
<note />
215215
</trans-unit>
216+
<trans-unit id="Error_MsBuildIsNetCoreMsBuild">
217+
<source>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.</source>
218+
<target state="new">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.</target>
219+
<note>{0} is the MSBuild directory path. Do not localize 'NuGet.exe', 'MSBuild', '.NET SDK', '.NET Framework', 'dotnet restore', 'Visual Studio'.</note>
220+
</trans-unit>
216221
<trans-unit id="Error_MsBuildTimedOut">
217222
<source>MsBuild timeout out while trying to get project to project references.</source>
218223
<target state="translated">프로젝트에서 프로젝트 참조를 가져오는 동안 MsBuild 시간이 초과되었습니다.</target>

0 commit comments

Comments
 (0)