13

I want to disable NuGet package restore on build and use the individual command for that. Is this possible?

My idea is to use something like this:

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

Update:

  • the package updating can be disabled by MSBuild.exe ... /p:RestorePackages=false
  • and it looks like .nuget\nuget.exe restore solution.sln restores the packages
1
  • 6
    You should post your update as an answer rather than an edit to the question.
    – Jeff Yates
    Jun 3, 2015 at 17:46

2 Answers 2

8

You can use "MSBuild /p:RestorePackages=false" to disable package restore on build command.

1
  • This worked for me. MSBuild was complaining about the NuGet version so I had to stop MSBuild from trying to restore, and instead ran nuget.exe from the command line before building. May 15, 2020 at 14:57
1

Nowadays, I suggest making your CLI approach more comprehensive and reliable.

Short plan

  1. Install Visual Studio Build Tools 2017
  2. Find proper MSBuild
  3. Clean solution
  4. Restore packages with nuget using correct MSBuild
  5. Build solution

Details

  1. Using Build Tools will give you independence from Visual Studio installation.

    Download Build Tools for Visual Studio 2017 from Visual Studio Downloads page (direct link)

    Command-line arguments documented here: Use command-line parameters to install Visual Studio 2017

    All workloads and components are listed here: Visual Studio Build Tools 2017 component directory

  2. Use PowerShell module VSSetup. And choose x86 or x64 MSBuild version

    Download it or install from here: Github: Microsoft/Visual Studio Setup PowerShell Module

  3. Run MSBuild with clean target

  4. Help nuget.exe to use proper MSBuild

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

  5. Run MSBuild with build target (you can add additional required parameters)


# 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 

As the result, you will not have any filesystem, PATH or Visual Studio dependencies. And your solution will be reusable on the local machine and a build server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.