如何使用Powershell强制Nuget Restore?

问题描述 投票:0回答:3

我想强制 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

提前致谢

visual-studio powershell package nuget nuget-package-restore
3个回答
4
投票

您可以在

Update-Package -reinstall
中尝试
Package Manager Console
命令。


1
投票

标准 powershell 不具备 NuGet 恢复功能。

如果您参考https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studiohttps://learn.microsoft.com/en -us/nuget/consume-packages/package-restore,你会看到有5种使用NuGet的方法。

  • Visual Studio(和 MSBuild.exe)
  • Mac 版 Visual Studio
  • dotnet CLI
  • NuGet.exe CLI
  • 包管理器控制台(在 Visual Studio 中)

powershell 中没有内置功能。

您唯一的选择是在上述工具之上进行构建。

  • 调用 dotnet.exe 恢复
  • 调用nuget.exe恢复
  • 调用msbuild.exe恢复。

1
投票

我不使用Update-Package,而是使用以下内容:

 & "C:\Program Files (x86)\Microsoft Visual Studio\2019\
       Community\MSBuild\Current\Bin\MSBuild.exe"
   /t:restore C:\code\projectdirectory

您可能需要将路径更改为

MSBuild.exe

不是本机 PowerShell,但它可以工作。

© www.soinside.com 2019 - 2024. All rights reserved.