Browse Source

Cli: use soluıtion's nuget.config & create it if it doesn't exist

pull/4782/head
Yunus Emre Kalkan 6 years ago
parent
commit
e68392ccee
  1. 8
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs
  2. 24
      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

@ -44,11 +44,11 @@ namespace Volo.Abp.Cli.ProjectModification
public async Task SwitchToNightlyPreview(CommandLineArgs commandLineArgs) public async Task SwitchToNightlyPreview(CommandLineArgs commandLineArgs)
{ {
_packageSourceManager.Add("ABP Nightly", "https://www.myget.org/F/abp-nightly/api/v3/index.json");
var solutionPath = GetSolutionPath(commandLineArgs); var solutionPath = GetSolutionPath(commandLineArgs);
var solutionFolder = GetSolutionFolder(commandLineArgs); var solutionFolder = GetSolutionFolder(commandLineArgs);
_packageSourceManager.Add(solutionFolder, "ABP Nightly", "https://www.myget.org/F/abp-nightly/api/v3/index.json");
await _nugetPackagesVersionUpdater.UpdateSolutionAsync( await _nugetPackagesVersionUpdater.UpdateSolutionAsync(
solutionPath, solutionPath,
true); true);
@ -60,11 +60,11 @@ namespace Volo.Abp.Cli.ProjectModification
public async Task SwitchToStable(CommandLineArgs commandLineArgs) public async Task SwitchToStable(CommandLineArgs commandLineArgs)
{ {
_packageSourceManager.Remove("ABP Nightly");
var solutionPath = GetSolutionPath(commandLineArgs); var solutionPath = GetSolutionPath(commandLineArgs);
var solutionFolder = GetSolutionFolder(commandLineArgs); var solutionFolder = GetSolutionFolder(commandLineArgs);
_packageSourceManager.Remove(solutionFolder, "ABP Nightly");
await _nugetPackagesVersionUpdater.UpdateSolutionAsync( await _nugetPackagesVersionUpdater.UpdateSolutionAsync(
solutionPath, solutionPath,
false, false,

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

@ -16,12 +16,21 @@ namespace Volo.Abp.Cli.ProjectModification
Logger = NullLogger<PackageSourceManager>.Instance; Logger = NullLogger<PackageSourceManager>.Instance;
} }
public void Add(string sourceKey, string sourceValue) public void Add(string solutionFolder, string sourceKey, string sourceValue)
{ {
var nugetConfigPath = GetNugetConfigPath(); var nugetConfigPath = GetNugetConfigPath(solutionFolder);
Logger.LogInformation($"Adding \"{sourceValue}\" ({sourceKey}) to nuget sources...");
if (!File.Exists(nugetConfigPath)) if (!File.Exists(nugetConfigPath))
{ {
File.WriteAllText(nugetConfigPath, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<configuration>\n" +
" <packageSources>\n" +
" <add key=\"nuget.org\" value=\"https://api.nuget.org/v3/index.json\" />\n" +
$" <add key=\"{sourceKey}\" value=\"{sourceValue}\" />\n" +
" </packageSources>\n" +
"</configuration>");
return; return;
} }
@ -32,8 +41,6 @@ namespace Volo.Abp.Cli.ProjectModification
return; return;
} }
Logger.LogInformation($"Adding \"{sourceValue}\" ({sourceKey}) to nuget sources...");
try try
{ {
var doc = new XmlDocument() { PreserveWhitespace = true }; var doc = new XmlDocument() { PreserveWhitespace = true };
@ -62,9 +69,9 @@ namespace Volo.Abp.Cli.ProjectModification
} }
} }
public void Remove(string sourceKey) public void Remove(string solutionFolder, string sourceKey)
{ {
var nugetConfigPath = GetNugetConfigPath(); var nugetConfigPath = GetNugetConfigPath(solutionFolder);
if (!File.Exists(nugetConfigPath)) if (!File.Exists(nugetConfigPath))
{ {
@ -101,10 +108,9 @@ namespace Volo.Abp.Cli.ProjectModification
} }
} }
private static string GetNugetConfigPath() private static string GetNugetConfigPath(string solutionFolder)
{ {
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), return Path.Combine(solutionFolder, "NuGet.Config");
"NuGet", "NuGet.Config");
} }
private static Stream GenerateStreamFromString(string s) private static Stream GenerateStreamFromString(string s)

Loading…
Cancel
Save