简体   繁体   English

如何从 PowerShell 下载项目引用的 Nuget 包?

[英]How to download Nuget packages referenced by project from PowerShell?

I'm creating .yml that automatically builds .NET Framework applications in GitHub Action.我正在创建.yml ,它会在 GitHub Action 中自动构建 .NET Framework 应用程序。

So, I try to build .NET Framework 4.7.2 Application via Msbuild.exe inside Powershell.因此,我尝试通过 Powershell 中的 Msbuild.exe 构建 .NET Framework 4.7.2 应用程序。

like this:像这样:

PS : & "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe" /t:myProject /p:Configuration=Release

However, you can see the following errors, and you cannot download the packages.但是,您会看到以下错误,并且无法下载软件包。

error : This project references NuGet package(s) that are missing on this computer.错误:此项目引用此计算机上缺少的 NuGet 包。 Use NuGet Package Restore to download them.使用 NuGet 包还原下载它们。 For more information, see http://go.microsoft.com/fwlink/?LinkID=322105 .有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkID=322105 The missing file is ..\packages\MaterialDesignThemes.4.5.0\build\MaterialDesignThemes.targets.缺少的文件是 ..\packages\MaterialDesignThemes.4.5.0\build\MaterialDesignThemes.targets。

How can I download the package that I need to build from Powershell through msbuild.exe?如何通过 msbuild.exe 从 Powershell 下载我需要构建的包?

(The dotnet CLI is not available because of the .NET Framework.) (由于 .NET Framework,dotnet CLI 不可用。)

Thanks!谢谢!

++ Visual Studio builds normally. ++ Visual Studio 正常构建。 What I want is a script that is built automatically for the CI/CD pipeline.我想要的是为 CI/CD 管道自动构建的脚本。

I found a solution.我找到了解决方案。 I can use the nuget CLI instead of the dotnet CLI.我可以使用 nuget CLI 而不是 dotnet CLI。

Solution :解决方案 :

  1. Download the nuget CLI下载 nuget CLI
  2. PS : nuget restore

https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore#restore-using-visual-studio here are all the ways. https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore#restore-using-visual-studio这里是所有方法。

If nothing helps you can try installing the packages manually using:如果没有任何帮助,您可以尝试使用以下方法手动安装软件包:

Install-Package <Package Name>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM