title: NuGet issues with packages.config, project references and the solutionwide packages folder
body: <p>We are starting to use NuGet and we are having some issues:</p>
  
  <h2>First some NuGet facts:</h2>
  
  <p><em>(Just to make sure that we have understood the premises for how NuGet works)</em></p>
  
  <ul>
  <li><p>The packages.config (located in project-root) is created and updated as you add, update or delete packages. Within this file the package version property reflects the full version that is in use, so in this sense it is also a state. It is possible to add the allowedVersions property to the package specification, which is then a restriction on which versions that can be updated. To make package restore work, this file need to be under source control.</p></li>
  <li><p>The packages folder is located in the solution-root and contains a downloaded version of the dependent packages in a subfolder named to match the package names (including version), to allow multiple versions of the same package to be used by different projects in a multi-project solution. It is advised not to source control these as they are binaries and the fact that package restore can recreate them when needed. When a package is updated a new folder that matches the update is created with the package in it. </p></li>
  <li><p>The project-files contains a reference to the packages in the packages folder, in order for builds to work and for visual studio to also be able to provide autocomplete, intellisense and more. When a package is updated the references in the project-file are updated to match the new location of the package in the packages folder.</p></li>
  </ul>
  
  <h2>Questions:</h2>
  
  <ol>
  <li><p>Since the packages.config file package entries contains the full version-info we constantly need to update the source control repo with changes. Or, we could ignore the changes, most of the time, but when just the version has changed we would (in most cases) be able to ignore them. 
  This seems very unnecessary as the NuGet restore should be able to know which versions are allowed (via allowedVersions).</p></li>
  <li><p>The allowedVersions property has to be manually added, something that is easily forgotten. We are using semantic versioning, so for us, when installing i.e. a Foo-1.1.0 version, allowedVersions="[1,2)" should be implied.</p></li>
  <li><p>When adding the allowedVersion then NuGet package restore doesn't seem to be able to find -prerelease assemblies (maybe a bug?).</p></li>
  <li><p>Why are packages handled by NuGet on a solution level? If you are working in a mix-and-match solution, which contains a project-A (repo-1) and project-B (repo-2), then the solution level packaging is not going to work well. That is, If you save that solution file in a separate location, things might still work afaik. But, if you then set up another solution which contains project-A (repo-1) and project-C (repo-3), then project-A would suddenly need a package-restore again, and worse, the project references would be changed to match the last change. Going back to the first solution will then have references that doesn't work. Checking in these will certainly make them not work for others.  </p></li>
  <li><p>On a package update, the project-file references are updated (to match the new foldernames with versionid in them) and will appear as an uncommitted change. Committing this change seems to be the norm, but in our opinion this should not be necessary.</p></li>
  </ol>
  
  <p><strong>Notes about ExcludeVersion</strong> (which could be suggested as a solution to the above problem:</p>
  
  <ul>
  <li><p>You can only provide that option when you manually perform NuGet commands, afaik. When installing/updating packages via the NuGet menus in Visual Studio that option cannot be used. Using any of the automated tools means that the foldername and project-reference has to be fixed manually afterwards.</p></li>
  <li><p>We know that ExcludeVersion is not the default setting, probably due to supporting the cases where someone is working in a multi-project solution, where the different projects depend on different versions of the same package.</p></li>
  </ul>
  
  <h2>Possible solutions?</h2>
  
  <p><em>(But, which may require substantial changes in the NuGet ecosystem?)</em></p>
  
  <p><strong>A - packages.config</strong></p>
  
  <p>I wish that each package element in packages.config could ditch allowedVersions and instead change version to be the range specifier. The packages element should also provide a way to separately identify which source to get the updates from. Finally, if an installed package follows Semantic Versioning then the version property should automatically setup the version-range according to the installed version.</p>
  
  <p>Sample packages.config:</p>
  
  <pre><code>`&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;packages&gt;
    &lt;package id="Foo" version="[1,2] source="Development Feed"&gt;
  &lt;/packages&gt;`
  </code></pre>
  
  <p>This would:</p>
  
  <ul>
  <li><p>Fix the issue with excessive commits of the package.config file, since the version property is no longer constantly updated.</p></li>
  <li><p>No need to remember to set the range for semantically versioned projects.</p></li>
  <li><p>Ensure that packages are fetched from the desired feed and that time is not wasted by looking for it in the wrong sources.</p></li>
  </ul>
  
  <p><strong>B - Packages folder and the names of installed packages within</strong></p>
  
  <p>I wish that the packages folder was located in each project-root and that the subfolder names was limited to the package-name only, excluding the version. 
  This would:</p>
  
  <ul>
  <li><p>Fix the issue with excessive commits of the project-files, since the project-references in the project-file now points to the same package-folder after an update.</p></li>
  <li><p>Allows projects to use different versions of the same package as they are then truly independent of each other.</p></li>
  </ul>
  
  <hr>
  
  <p><strong>We would be very happy to hear about solutions to the problems listed.</strong></p>