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

Ale*_*hov 9 msbuild visual-studio nuget

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

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

nuget.exe restore
msbuild.exe /p:NuGetRestorePackages=false
Run Code Online (Sandbox Code Playgroud)

更新:

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

小智 8

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


Vla*_*ykh 2

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

短期计划

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

细节

  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 安装 PowerShell 模块

  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 
Run Code Online (Sandbox Code Playgroud)

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