【发布时间】:2021-05-27 07:12:36
【问题描述】:
在一个 PowerShell 脚本中,我尝试安装最新版本的 .NET SDK 和运行时,然后卸载旧版本。
我目前正在使用来自 Microsoft 的 2 个资源:
- dotnet-install.ps1
- dotnet-core-uninstall-1.2.206301
SDK 和运行时列表:
Host (useful for support):
Version: 5.0.2
Commit: cb5f173b96
.NET SDKs installed:
No SDKs were found.
.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.25 [..\AppData\Local\Microsoft\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.25 [..\AppData\Local\Microsoft\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.12 [..\AppData\Local\Microsoft\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.2 [..\AppData\Local\Microsoft\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.25 [..\AppData\Local\Microsoft\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.12 [..\AppData\Local\Microsoft\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.2 [..\AppData\Local\Microsoft\dotnet\shared\Microsoft.NETCore.App]
我尝试通过运行以下命令来删除这些旧版本:
dotnet-core-uninstall remove --all --runtime
错误输出:
dotnet-core-uninstall : Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target
of an invocation.
At line:1 char:1
+ dotnet-core-uninstall remove --all --runtime
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Unhandled excep... an invocation.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
---> System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.DotNet.Tools.Uninstall.Shared.Commands.UninstallCommandExec.AskItAndReturnUserAnswer(IDictionary`2 bundles,
String userResponse)
at Microsoft.DotNet.Tools.Uninstall.Shared.Commands.UninstallCommandExec.Execute(IBundleCollector bundleCollector)
at Microsoft.DotNet.Tools.Uninstall.Shared.Configs.CommandLineConfigs.<>c__DisplayClass40_0.<.cctor>b__6()
at Microsoft.DotNet.Tools.Uninstall.Shared.Exceptions.ExceptionHandler.<>c__DisplayClass0_0.<HandleException>b__0()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean
wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters,
CultureInfo culture)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseErrorReporting>b__21_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__22_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseDirective>b__20_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseDebugDirective>b__11_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()
根据微软的说法,卸载工具有局限性..
在 Windows 上,该工具只能卸载使用以下安装程序之一安装的 SDK 和运行时:
- .NET SDK 和运行时安装程序。
- Visual Studio 之前版本中的 Visual Studio 安装程序 2019 版 16.3。
有没有人找到解决方法或其他方法来卸载这些由 dotnet-installer.ps1 脚本安装的 SDK 和运行时?我将不胜感激任何建议或提示。谢谢。
【问题讨论】:
标签: .net powershell .net-core automation