提问人:Jirka Picek 提问时间:11/13/2023 更新时间:11/14/2023 访问量:39
如何像 Visual Studio 一样从 CLI 还原 nuget 包
How to restore nuget packages from CLI like Visual Studio does
问:
我们有一个脚本来用 C# 构建我们的应用程序。我们的大部分项目都在 .NET7 构建良好,但我正在处理旧的 .NET Framework 项目。由于缺少库,我们无法升级这些项目(否则将花费大量时间,而我们现在没有),所以这不是办法。
我们已经安装了 Visual Studio 2022,我在其中找到了 MSBuild。当我尝试使用以下命令构建它时,它会在我之前在 Visual Studio 中打开解决方案时构建。
msbuild /p:OutputPath=<path-to-publish-folder>;Configuration=Release <path-to-csproj-file>
当它只是克隆存储库时,它不起作用。这是因为 Visual Studio 在文件夹中创建一个文件夹包,其中是 *.sln 文件,并且我们在同一文件夹中有 CLI 生成脚本。
如何从安装了 .NET7 SDK 和 Visual Studio 2022?目标文件夹应为 /packages。
我试过了,也.这两个命令都会根据引用的 netstandard 依赖项目的输出还原 nuget 包,但不会还原主项目的 nget。msbuild <path-to-csproj> -t:restore
msbuild project.sln -t:restore
我也试过了,但输出是:dotnet msbuild <path-to-csproj> /t:restore
All projects are up-to-date for restore.
该解决方案是在 Visual Studio 中创建的,所有 nuget 依赖项都通过 Visual Studio 进行管理。
我应该使用哪个命令将 nugets 还原到 ./packages 文件夹,就像 Visual Studio 在打开项目时所做的那样?
答:
可以使用 dotnet restore
还原依赖项,并添加 a 来强制执行。-f
评论
nuget.exe