【问题标题】:How to disable nuget package restore with msbuild command line options?如何使用 msbuild 命令行选项禁用 nuget 包还原?
【发布时间】:2014-03-28 11:14:01
【问题描述】:

我想在构建时禁用 NuGet 包还原并为此使用单独的命令。这可能吗?

我的想法是使用这样的东西:

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

更新:

  • 可以通过MSBuild.exe ... /p:RestorePackages=false禁用包更新
  • 看起来.nuget\nuget.exe restore solution.sln 恢复了包

【问题讨论】:

  • 您应该将更新发布为答案,而不是对问题的编辑。

标签: visual-studio msbuild nuget


【解决方案1】:

您可以使用“MSBuild /p:RestorePackages=false”在构建命令上禁用包恢复。

【讨论】:

  • 这对我有用。 MSBuild 抱怨 NuGet 版本,所以我不得不阻止 MSBuild 尝试恢复,而是在构建之前从命令行运行 nuget.exe。
【解决方案2】:

现在,我建议让您的 CLI 方法更加全面和可靠。

短期计划

  1. 安装 Visual Studio 构建工具 2017
  2. 找到合适的 MSBuild
  3. 清洁解决方案
  4. 使用 nuget 使用正确的 MSBuild 恢复包
  5. 构建解决方案

详情

  1. 使用构建工具将使您独立于 Visual Studio 安装

    Visual Studio Downloads pagedirect link)下载Build Tools for Visual Studio 2017

    此处记录的命令行参数:Use command-line parameters to install Visual Studio 2017

    此处列出了所有工作负载和组件:Visual Studio Build Tools 2017 component directory

  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 

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

【讨论】:

    猜你喜欢
    • 2017-04-19
    • 2018-07-31
    • 2015-09-04
    • 2014-04-13
    • 2021-03-20
    • 1970-01-01
    • 1970-01-01
    • 2015-07-06
    • 1970-01-01
    相关资源
    最近更新 更多