我想强制 NuGet 恢复我的 NuGet 包。转到我的解决方案目录并输入
NuGet restore
,即使使用最新下载的 NuGet.exe
也不起作用。
如here所述,我可以在 Powershell 提示符下使用
Update-Package
命令执行此操作(因为我不喜欢使用 Visual Studio 环境)。
但是,我的Powershell似乎不理解
Update-Package
,尽管我有+5版本:
PowerShell Prompt> Get-Host | Select-Object Version
Version
-------
5.1.19041.1023
PowerShell Prompt> Update-Package -reinstall
Update-Package : The term 'Update-Package' is not recognized as the name of a cmdlet, function,
script file, or operable program.
Check the spelling of the name, or if a path was included, verify that
the path is correct and try again.
At line:1 char:1
+ Update-Package -reinstall
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Update-Package:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
如何才能在 Powershell 中成功启动
Update-Package
?
提前致谢
您可以在
Update-Package -reinstall
中尝试 Package Manager Console
命令。
标准 powershell 不具备 NuGet 恢复功能。
如果您参考https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio和https://learn.microsoft.com/en -us/nuget/consume-packages/package-restore,你会看到有5种使用NuGet的方法。
powershell 中没有内置功能。
您唯一的选择是在上述工具之上进行构建。
我不使用Update-Package,而是使用以下内容:
& "C:\Program Files (x86)\Microsoft Visual Studio\2019\
Community\MSBuild\Current\Bin\MSBuild.exe"
/t:restore C:\code\projectdirectory
您可能需要将路径更改为
MSBuild.exe
。
不是本机 PowerShell,但它可以工作。