NuGet package development cycle

May 3, 2011 at 10:48 PM

I'm working on NuGet packages in a Visual Studio project. On build I publish a new version of my nuget package to a repository (a directory on my system).

I don't increment version numbers after each change, i only want to do that on really published versions.

To test out changes to the package in my solution where I already reference the package I want to pull in a new version of the package that has the same version number.

install-package does not have a -force option to force uninstall/install of the package with an unchanged version number.

I wrote a function that i added to the init.ps1 of a core package that all other packages are dependent on:

function global:Update-FactoryPackages
	$factoryPackages = Get-ChildItem -Path product:\Dist\NuGet-Factory
	if ($factoryPackages -ne $null) {
		$factoryPackages | Foreach-Object {
			$packageBasename = []::GetFilenameWithoutExtension($_.FullName)
			$packageName = $packageBasename.split('.')[0]
			Write-Host "(Re)installing package $packageName"
			if ((get-package | Select-Object -ExpandProperty ID) -contains $packageName) {
				Uninstall-Package -Id $packageName -Force
			Install-Package -Id $packageName -Source (Convert-Path -Path product:\Dist\NuGet-Factory)

I'm using a shared packages folder for my solution. I'm not happy with this approach, and it does not work well. I get errors on some packages with this approach.  And it also adds all packages in my packages repository to the project i'm executing this code from.

Any ideas on a good development cycle with packages?



May 4, 2011 at 1:43 AM
Edited May 8, 2011 at 9:56 PM

NOTE 8/5/2011: updated the code below

Ok, I will answer my own question with a first solution to 'refresh' a set of packages. You can use the following script.

Save as Update-NuGetPackages.ps1 and put next to NuGet.exe.


  Update NuGet packages with same version of package.

  During the development cycle version numbers of packages are often not changed,
  but the contents of the package itself is updates. Update-NuGetPackages.ps1
  refreshes all packages in a given packages directory.
  By default don't specify any sources, so NuGet.exe (version 1.3 and later) will use
  the NuGet.config which is stored in the AppData folder and shared between Visual Studio
  and NuGet.exe

 .PARAMETER  PackagesPath
  Path to folder containing the packages to refresh.

 .PARAMETER  PackagesSource
  Source where packages should be installed from. Post version 1.3 of NuGet.exe
  supports specifying multiple sources separated by ';'.
  Source paths may not contain PSDrives in its path, like product:\mypath.
 .PARAMETER  IncludeDefaultSource
  Switch parameter to specify that the default NuGet packages source should be included as a
  packages source. Don't specify this switch and dont use the PackagesSource
  parameter to let NuGet.exe use the sources specified in the NuGet.config.
  This functionality is available after release version 1.3 of NuGet.exe.
  If used together with the PackagesSource parameter a version newer than
  version 1.3 of NuGet.exe is required.

  PS C:\> Update-NuGetPackages.ps1 -PackagesSource c:\MyProduct\Packages
  Deleting package 'EntityFramework' version '4.1.10331.0'
  Deleting package 'MacawSolutionsFactory-Core' version '1.0.0'
  Deleting package 'MacawSolutionsFactory-Spf2010' version '1.0.0'
  Deleting package 'T4Scaffolding' version '1.0.0'
  Reinstalling package 'EntityFramework' version '4.1.10331.0'
  Successfully installed 'EntityFramework 4.1.10331.0'.
  Reinstalling package 'MacawSolutionsFactory-Core' version '1.0.0'
  'T4Scaffolding (= 1.0.0)' not installed. Attempting to retrieve dependency from source...
  Dependency 'EntityFramework (= 4.1.10311.0)' already installed.
  Successfully installed 'T4Scaffolding 1.0.0'.
  Successfully installed 'MacawSolutionsFactory-Core 1.0.0'.
  Reinstalling package 'MacawSolutionsFactory-Spf2010' version '1.0.0'
  Dependency 'T4Scaffolding (= 1.0.0)' already installed.
  Dependency 'EntityFramework (= 4.1.10311.0)' already installed.
  Successfully installed 'MacawSolutionsFactory-Spf2010 1.0.0'.
  Reinstalling package 'T4Scaffolding' version '1.0.0'
  Dependency 'EntityFramework (= 4.1.10311.0)' already installed.
  'T4Scaffolding 1.0.0' already installed.

  PS C:\> Update-NuGetPackages.ps1 -PackagesSource c:\MyProduct\Packages `
          -PackagesSource "c:\Dist\Feed1;c:\Dist\Feed2" -IncludeDefaultSource

  This script must be located next to NuGet.exe.
  This script requires a version later than the release version 1.3 of NuGet.exe
  when specifying multiple sources on the commandline and/or using the IncludeDefaultSource
  Version: 1.0
  Author: Serge van den Oever (
 [Parameter(Position=0, Mandatory=$true)][String]$PackagesPath,
 [Parameter(Position=1, Mandatory=$false)][String]$PackagesSource = '',
 [Parameter(Position=2, Mandatory=$false)][Switch]$IncludeDefaultSource = $false

$nugetDefaultSource= ''

function Get-ScriptDirectory
  $Invocation = (Get-Variable MyInvocation -Scope 1).Value
  Split-Path $Invocation.MyCommand.Path

$nugetExe = Join-Path -Path (Get-ScriptDirectory) -ChildPath 'nuget.exe'
if (-not (Test-Path -Path $nugetExe)) { throw ("Expected NuGet.exe at path '{0}'" -f $nugetExe) }

if (-not (Test-Path -Path $PackagesPath)) { throw ("Specified PackagesPath '{0}' does not exist" -f $PackagesPath) }
$PackagesPath = Convert-Path -Path $PackagesPath

# Collect packages
$packageFolders = Get-ChildItem -Path $PackagesPath | Where-Object {$_.psIsContainer -eq $true}

$packages = @()
if ($packageFolders -ne $null) {
 $packageFolders | ForEach-Object {
  $packageFolder = Convert-Path -Path $_.FullName # Handle case where PSDrive is specified
  $packageFolderName = Split-Path -Path $packageFolder -Leaf
  $parts = $packageFolderName.split('.')
  $packageName = $parts[0]
  $packageVersion = $parts[1..$($parts.length-1)] -join '.'
  $packages += @{
   Name = $packageName;
   Version = $packageVersion;
   Folder = $packageFolder;

# Delete all package folders
$packages | ForEach-Object {
 Write-Host ("Deleting package '{0}' version '{1}'" -f $_.Name, $_.Version)
 Remove-Item -Recurse -Force -Path $_.Folder -ErrorAction SilentlyContinue
 if (Test-Path -Path $_.Folder) { Write-Warning ("Can't remove folder '{0}'. Make sure it is not locked." -f $_.Folder) }

# Reinstall all packages
$packages | ForEach-Object {
 Write-Host ("Reinstalling package '{0}' version '{1}'" -f $_.Name, $_.Version)
 if ($IncludeDefaultSource) {
  $source = $nugetDefaultSource
 } else {
  $source = ''
 if ($PackagesSource -ne '') {
  if ($source -ne '') { $source += ';' }
  $source += (Convert-Path -Path $PackagesSource)
 if ($source -ne '') {
  & $nugetExe install $_.Name -Version $_.Version -Source $source -OutputDirectory $PackagesPath
 } else {
  & $nugetExe install $_.Name -Version $_.Version -OutputDirectory $PackagesPath

 if (-not (Test-Path -Path $_.Folder)) {
  New-Item -Path $_.Folder -Type Directory -Force
  Write-Warning ("Failed to reinstall package '{0}' version '{1}'. Created dummy directory '$($_.Folder). Fix error and try again." -f $_.Name, $_.Version)

Write-Host 'Done.'

May 4, 2011 at 5:50 AM

I wonder if we should add a flag to Update-Package such as Update-Package -reinstall

May 8, 2011 at 9:57 PM

Yes please!

PS: I updated the code in my previous post.

Jun 21, 2011 at 10:09 PM

> Update-Package -reinstall


Jun 23, 2011 at 8:25 AM

> Update-Package -reinstall


Dec 9, 2011 at 1:58 AM

Update-Package -reinstall 


(or Update-Package -force

Dec 15, 2011 at 3:17 AM
SkySigal wrote:

Update-Package -reinstall 


Dec 15, 2011 at 3:31 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Dec 15, 2011 at 3:32 AM

I created the work item Please feel free to vote it up so that we can triage it accordingly.