Browse Source

Merge pull request #18999 from abpframework/EngincanV/revert-cli-package-source-mapping

Revert "CLI: Add nightly package source to the package source mappings"
pull/19000/head
Enis Necipoglu 2 years ago
committed by GitHub
parent
commit
bfdb8a8447
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 8
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs
  2. 82
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackageSourceManager.cs

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

@ -132,7 +132,6 @@ public class PackagePreviewSwitcher : ITransientDependency
var solutionAngularFolder = GetSolutionAngularFolder(solutionFolder);
_packageSourceManager.Remove(solutionFolder, "ABP Nightly");
_packageSourceManager.RemovePackageSourceMapping(solutionFolder, "ABP Nightly");
await _nugetPackagesVersionUpdater.UpdateSolutionAsync(
solutionPath,
@ -178,13 +177,10 @@ public class PackagePreviewSwitcher : ITransientDependency
foreach (var project in projects)
{
var folder = Path.GetDirectoryName(project);
var solutionFolder = FindSolutionFolder(project) ?? folder;
_packageSourceManager.Add(solutionFolder, "ABP Nightly",
_packageSourceManager.Add(FindSolutionFolder(project) ?? folder, "ABP Nightly",
"https://www.myget.org/F/abp-nightly/api/v3/index.json");
_packageSourceManager.AddPackageSourceMapping(solutionFolder, "ABP Nightly", "Volo.*");
await _nugetPackagesVersionUpdater.UpdateSolutionAsync(
project,
true);
@ -204,8 +200,6 @@ public class PackagePreviewSwitcher : ITransientDependency
_packageSourceManager.Add(solutionFolder, "ABP Nightly",
"https://www.myget.org/F/abp-nightly/api/v3/index.json");
_packageSourceManager.AddPackageSourceMapping(solutionFolder, "ABP Nightly", "Volo.*");
if (solutionPath != null)
{

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

@ -108,88 +108,6 @@ public class PackageSourceManager : ITransientDependency
}
}
public void AddPackageSourceMapping(string solutionFolder, string sourceKey, string sourceValue)
{
var nugetConfigPath = GetNugetConfigPath(solutionFolder);
if (!File.Exists(nugetConfigPath))
{
return;
}
var fileContent = File.ReadAllText(nugetConfigPath);
if (fileContent.Contains($"<packageSource key=\"{sourceKey}\">"))
{
return;
}
try
{
var doc = new XmlDocument() { PreserveWhitespace = true };
doc.Load(GenerateStreamFromString(fileContent));
var sourceNodes = doc.SelectNodes("/configuration/packageSourceMapping");
var newNode = doc.CreateElement("packageSource");
var keyAttr = doc.CreateAttribute("key");
keyAttr.Value = sourceKey;
newNode.Attributes.Append(keyAttr);
var packageNode = doc.CreateElement("package");
var patternAttr = doc.CreateAttribute("pattern");
patternAttr.Value = sourceValue;
packageNode.Attributes.Append(patternAttr);
newNode.AppendChild(packageNode);
sourceNodes?[0]?.AppendChild(newNode);
File.WriteAllText(nugetConfigPath, doc.OuterXml);
}
catch
{
Logger.LogWarning($"Adding \"{sourceValue}\" ({sourceKey}) to package source mapping FAILED.");
}
}
public void RemovePackageSourceMapping(string solutionFolder, string sourceKey)
{
var nugetConfigPath = GetNugetConfigPath(solutionFolder);
if (!File.Exists(nugetConfigPath))
{
return;
}
var fileContent = File.ReadAllText(nugetConfigPath);
if (!fileContent.Contains($"<packageSource key=\"{sourceKey}\">"))
{
return;
}
Logger.LogInformation($"Removing \"{sourceKey}\" from nuget package source mappings...");
try
{
var doc = new XmlDocument() { PreserveWhitespace = true };
doc.Load(GenerateStreamFromString(fileContent));
var nodes = doc.SelectNodes($"/configuration/packageSourceMapping/packageSource[@key='{sourceKey}']");
if (nodes != null && nodes.Count > 0)
{
nodes[0]!.ParentNode?.RemoveChild(nodes[0]);
}
File.WriteAllText(nugetConfigPath, doc.OuterXml);
}
catch
{
Logger.LogWarning($"Removing \"{sourceKey}\" from package source mappings FAILED.");
}
}
private static string GetNugetConfigPath(string solutionFolder)
{
return Path.Combine(solutionFolder, "NuGet.Config");

Loading…
Cancel
Save