Reputation: 13522
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:
MSBuild.exe ... /p:RestorePackages=false
.nuget\nuget.exe restore solution.sln
restores the packages Upvotes: 14
Views: 13353
Reputation: 91
You can use "MSBuild /p:RestorePackages=false" to disable package restore on build command.
Upvotes: 9
Reputation: 4730
Nowadays, I suggest making your CLI approach more comprehensive and reliable.
Short plan
Details
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
Use PowerShell module VSSetup
. And choose x86 or x64 MSBuild version
Download it or install from here: Github: Microsoft/Visual Studio Setup PowerShell Module
Run MSBuild with clean
target
Help nuget.exe
to use proper MSBuild
nuget.exe restore -MSBuildPath "C:\..."
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.
Upvotes: 2