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

pull/4782/head
Yunus Emre Kalkan 5 years ago
parent 0f03115bad
commit e68392ccee

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

@ -16,12 +16,21 @@ namespace Volo.Abp.Cli.ProjectModification
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))
{
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;
}
@ -32,8 +41,6 @@ namespace Volo.Abp.Cli.ProjectModification
return;
}
Logger.LogInformation($"Adding \"{sourceValue}\" ({sourceKey}) to nuget sources...");
try
{
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))
{
@ -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),
"NuGet", "NuGet.Config");
return Path.Combine(solutionFolder, "NuGet.Config");
}
private static Stream GenerateStreamFromString(string s)

Loading…
Cancel
Save