Browse Source

Adding PackageSourceMapping while adding new sources

pull/21049/head
enisn 1 year ago
parent
commit
94a8c1f65f
No known key found for this signature in database GPG Key ID: A052619F04155D1C
  1. 5
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs
  2. 44
      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);
_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(
project,
@ -213,7 +213,8 @@ public class PackagePreviewSwitcher : ITransientDependency
var solutionAngularFolder = GetSolutionAngularFolder(solutionFolder);
_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)
{

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

@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Xml;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
@ -16,7 +17,7 @@ public class PackageSourceManager : ITransientDependency
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);
@ -61,6 +62,11 @@ public class PackageSourceManager : ITransientDependency
sourceNodes?[0]?.AppendChild(newNode);
if (packageMappingPatterns.Any())
{
ConfigurePackageSourceMappings(doc, sourceKey, packageMappingPatterns);
}
File.WriteAllText(nugetConfigPath, doc.OuterXml);
}
catch
@ -69,6 +75,42 @@ public class PackageSourceManager : ITransientDependency
}
}
protected virtual void ConfigurePackageSourceMappings(XmlDocument doc, string sourceKey, string[] packageMappingPatterns)
{
var packageMappingNodes = doc.SelectNodes("/configuration/packageSourceMapping");
if (packageMappingNodes == null || packageMappingNodes.Count == 0)
{
var packageSourcesNode = doc.SelectSingleNode("/configuration/packageSources");
var packageMappingNode = doc.CreateElement("packageSourceMapping");
foreach (var pattern in packageMappingPatterns)
{
var patternNode = doc.CreateElement("packageSource");
var patternAttr = doc.CreateAttribute("key");
patternAttr.Value = pattern;
patternNode.Attributes.Append(patternAttr);
packageMappingNode.AppendChild(patternNode);
}
packageSourcesNode?.ParentNode?.InsertAfter(packageMappingNode, packageSourcesNode);
}
else
{
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)
{
var nugetConfigPath = GetNugetConfigPath(solutionFolder);

Loading…
Cancel
Save