Browse Source

Merge pull request #21049 from abpframework/9.0-cli-package-source-mapping

Adding PackageSourceMapping while adding new sources
pull/21058/head
Engincan VESKE 2 years ago
committed by GitHub
parent
commit
2880b5fd67
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 5
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs
  2. 33
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackageSourceManager.cs

5
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

@ -193,7 +193,7 @@ public class PackagePreviewSwitcher : ITransientDependency
var folder = Path.GetDirectoryName(project); var folder = Path.GetDirectoryName(project);
_packageSourceManager.Add(FindSolutionFolder(project) ?? folder, "ABP Nightly", _packageSourceManager.Add(FindSolutionFolder(project) ?? folder, "ABP Nightly",
"https://www.myget.org/F/abp-nightly/api/v3/index.json"); "https://www.myget.org/F/abp-nightly/api/v3/index.json", "Volo.*");
await _nugetPackagesVersionUpdater.UpdateSolutionAsync( await _nugetPackagesVersionUpdater.UpdateSolutionAsync(
project, project,
@ -213,7 +213,8 @@ public class PackagePreviewSwitcher : ITransientDependency
var solutionAngularFolder = GetSolutionAngularFolder(solutionFolder); var solutionAngularFolder = GetSolutionAngularFolder(solutionFolder);
_packageSourceManager.Add(solutionFolder, "ABP Nightly", _packageSourceManager.Add(solutionFolder, "ABP Nightly",
"https://www.myget.org/F/abp-nightly/api/v3/index.json"); "https://www.myget.org/F/abp-nightly/api/v3/index.json",
"Volo.*");
if (solutionPath != null) if (solutionPath != null)
{ {

33
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackageSourceManager.cs

@ -1,5 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using System.Xml; using System.Xml;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
@ -16,7 +17,7 @@ public class PackageSourceManager : ITransientDependency
Logger = NullLogger<PackageSourceManager>.Instance; Logger = NullLogger<PackageSourceManager>.Instance;
} }
public void Add(string solutionFolder, string sourceKey, string sourceValue) public void Add(string solutionFolder, string sourceKey, string sourceValue, params string[] packageMappingPatterns)
{ {
var nugetConfigPath = GetNugetConfigPath(solutionFolder); var nugetConfigPath = GetNugetConfigPath(solutionFolder);
@ -61,6 +62,11 @@ public class PackageSourceManager : ITransientDependency
sourceNodes?[0]?.AppendChild(newNode); sourceNodes?[0]?.AppendChild(newNode);
if (packageMappingPatterns.Any())
{
ConfigurePackageSourceMappings(doc, sourceKey, packageMappingPatterns);
}
File.WriteAllText(nugetConfigPath, doc.OuterXml); File.WriteAllText(nugetConfigPath, doc.OuterXml);
} }
catch catch
@ -69,6 +75,31 @@ public class PackageSourceManager : ITransientDependency
} }
} }
protected virtual void ConfigurePackageSourceMappings(XmlDocument doc, string sourceKey, string[] packageMappingPatterns)
{
var packageMappingNodes = doc.SelectNodes("/configuration/packageSourceMapping");
if (packageMappingNodes == null)
{
// If there is no packageSourceMapping node, leave it as it is.
Logger.LogWarning($"<packageSourceMapping> node not found in 'NuGet.Config' file. Skipping adding patterns for '{sourceKey}' source.");
return;
}
var packageSourceNode = doc.CreateElement("packageSource");
var sourceAttr = doc.CreateAttribute("key");
sourceAttr.Value = sourceKey;
packageSourceNode.Attributes.Append(sourceAttr);
packageMappingNodes[0]?.AppendChild(packageSourceNode);
foreach (var pattern in packageMappingPatterns)
{
var packageNode = doc.CreateElement("package");
var patternAttr = doc.CreateAttribute("pattern");
patternAttr.Value = pattern;
packageNode.Attributes.Append(patternAttr);
packageSourceNode.AppendChild(packageNode);
}
}
public void Remove(string solutionFolder, string sourceKey) public void Remove(string solutionFolder, string sourceKey)
{ {
var nugetConfigPath = GetNugetConfigPath(solutionFolder); var nugetConfigPath = GetNugetConfigPath(solutionFolder);

Loading…
Cancel
Save