Browse Source

Support custom NuGet package directory.

NuGet allows a solution to override the standard packages directory
with a repositoryPath setting in the NuGet.config file at the solution
level in the .nuget directory.

  <configuration>
    <config>
      <add key="repositoryPath"
        value="../../MyPackages" />
    </config>
  </configuration>

This is now supported by SharpDevelop.
pull/503/head
Matt Ward 12 years ago
parent
commit
82e98ec949
  1. 17
      src/AddIns/Misc/PackageManagement/Project/Src/Design/FakeSettings.cs
  2. 5
      src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementOptions.cs
  3. 4
      src/AddIns/Misc/PackageManagement/Project/Src/RegisteredPackageSourceSettings.cs
  4. 2
      src/AddIns/Misc/PackageManagement/Project/Src/SharpDevelopPackageManagerFactory.cs
  5. 15
      src/AddIns/Misc/PackageManagement/Project/Src/SolutionPackageRepositoryPath.cs
  6. 24
      src/AddIns/Misc/PackageManagement/Test/Src/SolutionPackageRepositoryPathTests.cs

17
src/AddIns/Misc/PackageManagement/Project/Src/Design/FakeSettings.cs

@ -18,6 +18,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using NuGet; using NuGet;
namespace ICSharpCode.PackageManagement.Design namespace ICSharpCode.PackageManagement.Design
@ -36,6 +38,8 @@ namespace ICSharpCode.PackageManagement.Design
public Dictionary<string, IList<KeyValuePair<string, string>>> Sections public Dictionary<string, IList<KeyValuePair<string, string>>> Sections
= new Dictionary<string, IList<KeyValuePair<string, string>>>(); = new Dictionary<string, IList<KeyValuePair<string, string>>>();
public const string ConfigSectionName = "config";
public FakeSettings() public FakeSettings()
{ {
Sections.Add(RegisteredPackageSourceSettings.PackageSourcesSectionName, PackageSources); Sections.Add(RegisteredPackageSourceSettings.PackageSourcesSectionName, PackageSources);
@ -200,7 +204,11 @@ namespace ICSharpCode.PackageManagement.Design
public string GetValue(string section, string key, bool isPath) public string GetValue(string section, string key, bool isPath)
{ {
throw new NotImplementedException(); if (Sections.ContainsKey(section)) {
var matchedSection = Sections[section];
return matchedSection.FirstOrDefault(item => item.Key == key).Value;
}
return null;
} }
public IList<KeyValuePair<string, string>> GetValues(string section, bool isPath) public IList<KeyValuePair<string, string>> GetValues(string section, bool isPath)
@ -212,5 +220,12 @@ namespace ICSharpCode.PackageManagement.Design
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void SetRepositoryPathSetting(string fullPath)
{
var items = new List<KeyValuePair<string, string>> ();
items.Add (new KeyValuePair<string, string>("repositoryPath", fullPath));
Sections.Add(ConfigSectionName, items);
}
} }
} }

5
src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementOptions.cs

@ -95,5 +95,10 @@ namespace ICSharpCode.PackageManagement
{ {
properties.SetList(RecentPackagesPropertyName, recentPackages); properties.SetList(RecentPackagesPropertyName, recentPackages);
} }
public string GetCustomPackagesDirectory()
{
return registeredPackageSourceSettings.Settings.GetRepositoryPath();
}
} }
} }

4
src/AddIns/Misc/PackageManagement/Project/Src/RegisteredPackageSourceSettings.cs

@ -204,5 +204,9 @@ namespace ICSharpCode.PackageManagement
packageSources = null; packageSources = null;
} }
} }
public ISettings Settings {
get { return settings; }
}
} }
} }

2
src/AddIns/Misc/PackageManagement/Project/Src/SharpDevelopPackageManagerFactory.cs

@ -32,7 +32,7 @@ namespace ICSharpCode.PackageManagement
: this( : this(
new SharpDevelopPackageRepositoryFactory(), new SharpDevelopPackageRepositoryFactory(),
new SharpDevelopProjectSystemFactory(), new SharpDevelopProjectSystemFactory(),
new PackageManagementOptions()) PackageManagementServices.Options)
{ {
} }

15
src/AddIns/Misc/PackageManagement/Project/Src/SolutionPackageRepositoryPath.cs

@ -25,12 +25,11 @@ namespace ICSharpCode.PackageManagement
{ {
public class SolutionPackageRepositoryPath public class SolutionPackageRepositoryPath
{ {
string packagesRelativeDirectory;
ISolution solution; ISolution solution;
DefaultPackagePathResolver pathResolver; DefaultPackagePathResolver pathResolver;
public SolutionPackageRepositoryPath(IProject project) public SolutionPackageRepositoryPath(IProject project)
: this(project, new PackageManagementOptions()) : this(project, PackageManagementServices.Options)
{ {
} }
@ -41,14 +40,18 @@ namespace ICSharpCode.PackageManagement
public SolutionPackageRepositoryPath(ISolution solution, PackageManagementOptions options) public SolutionPackageRepositoryPath(ISolution solution, PackageManagementOptions options)
{ {
packagesRelativeDirectory = options.PackagesDirectory;
this.solution = solution; this.solution = solution;
GetSolutionPackageRepositoryPath(); PackageRepositoryPath = GetSolutionPackageRepositoryPath(options);
} }
void GetSolutionPackageRepositoryPath() string GetSolutionPackageRepositoryPath(PackageManagementOptions options)
{ {
PackageRepositoryPath = Path.Combine(solution.Directory, packagesRelativeDirectory); string customPath = options.GetCustomPackagesDirectory ();
if (!String.IsNullOrEmpty (customPath)) {
return customPath;
}
return Path.Combine (solution.Directory, options.PackagesDirectory);
} }
public string PackageRepositoryPath { get; private set; } public string PackageRepositoryPath { get; private set; }

24
src/AddIns/Misc/PackageManagement/Test/Src/SolutionPackageRepositoryPathTests.cs

@ -32,8 +32,9 @@ namespace PackageManagement.Tests
{ {
SolutionPackageRepositoryPath repositoryPath; SolutionPackageRepositoryPath repositoryPath;
IProject testProject; IProject testProject;
PackageManagementOptions options; TestablePackageManagementOptions options;
ISolution solution; ISolution solution;
FakeSettings settings;
void CreateSolutionPackageRepositoryPath() void CreateSolutionPackageRepositoryPath()
{ {
@ -61,6 +62,12 @@ namespace PackageManagement.Tests
void CreateOptions() void CreateOptions()
{ {
options = new TestablePackageManagementOptions(); options = new TestablePackageManagementOptions();
settings = options.FakeSettings;
}
void SolutionNuGetConfigFileHasCustomPackagesPath(string fullPath)
{
settings.SetRepositoryPathSetting(fullPath);
} }
[Test] [Test]
@ -109,5 +116,20 @@ namespace PackageManagement.Tests
Assert.AreEqual(expectedInstallPath, installPath); Assert.AreEqual(expectedInstallPath, installPath);
} }
[Test]
public void PackageRepositoryPath_SolutionHasNuGetFileThatOverridesDefaultPackagesRepositoryPath_OverriddenPathReturned()
{
CreateOptions();
CreateSolution(@"d:\projects\MySolution\MySolution.sln");
options.PackagesDirectory = "Packages";
SolutionNuGetConfigFileHasCustomPackagesPath(@"d:\Team\MyPackages");
CreateSolutionPackageRepositoryPath(solution);
string expectedPath = @"d:\Team\MyPackages";
string path = repositoryPath.PackageRepositoryPath;
Assert.AreEqual(expectedPath, path);
}
} }
} }

Loading…
Cancel
Save