如何使用msbuild命令行选项禁用nuget包还原?

14

我想在构建时禁用NuGet软件包还原,并使用单独的命令进行操作。这是否可行?

我的想法是像这样使用:

nuget.exe restore
msbuild.exe /p:NuGetRestorePackages=false

更新:

  • 可以通过MSBuild.exe ... /p:RestorePackages=false禁用软件包更新
  • .nuget\nuget.exe restore solution.sln似乎会还原软件包

更新:

  • 可以通过MSBuild.exe ... /p:RestorePackages=false禁用软件包更新
  • .nuget\nuget.exe restore solution.sln似乎会还原软件包

6
你应该将更新作为回答发布,而不是编辑问题。 - Jeff Yates
2个回答

8
你可以使用 "MSBuild /p:RestorePackages=false" 命令来在构建时禁用包恢复功能。

这对我有用。MSBuild抱怨NuGet版本,所以我不得不停止MSBuild尝试还原,而是在构建之前从命令行运行nuget.exe。 - Frank Hoffman

2
现在,我建议你让CLI方法更加全面和可靠。 简短计划
  1. 安装Visual Studio Build Tools 2017
  2. 找到适当的MSBuild
  3. 清除解决方案
  4. 使用nuget 使用正确的MSBuild还原包
  5. 构建解决方案

Details

  1. 使用构建工具将使您摆脱对Visual Studio安装的依赖。

    Visual Studio下载页面直接链接)下载Visual Studio 2017构建工具

    命令行参数在此处记录:使用命令行参数安装Visual Studio 2017

    所有工作负载和组件均在此处列出:Visual Studio Build Tools 2017组件目录

  2. 使用PowerShell模块VSSetup。并选择x86或x64 MSBuild版本

    从此处下载或安装:Github: Microsoft/Visual Studio Setup PowerShell Module

  3. 使用clean目标运行MSBuild

  4. 帮助nuget.exe使用正确的MSBuild

    nuget.exe restore -MSBuildPath "C:\..."

  5. 使用build目标运行MSBuild(您可以添加其他必需的参数)


# 1. Find MS Build  

Import-Module $PSScriptRoot\VSSetup\VSSetup.psd1

$msBuildPath = (Get-VSSetupInstance | Select-VSSetupInstance -Version 15.0 -Product Microsoft.VisualStudio.Product.BuildTools).InstallationPath

if ([System.IntPtr]::Size -eq 8)
{
    $global:msbuildPath = Join-Path $msBuildPath 'MSBuild\15.0\Bin\amd64'
}
else
{
    $global:msbuildPath = Join-Path $msBuildPath 'MSBuild\15.0\Bin'
}

Write-Output "Using MSBuild from $global:msbuildPath"
Write-Output "MSBuild /version"

$msbuild = Join-Path $global:msbuildPath msbuild

& $msbuild /version


# 2. Clean

& $msbuild "$sln_file" /t:Clean /v:q /nologo


# 3. Restore

$nuget = Join-Path $PSScriptRoot "\.nuget\nuget.exe"
& $nuget restore -MSBuildPath $global:msbuildPath


# 4. Build

& $msbuild "$sln_file" /t:Build /v:q /nologo 

因此,您将不会有任何文件系统、路径或Visual Studio的依赖。您的解决方案将可在本地机器和构建服务器上重复使用。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接