Skip to content

Commit

Permalink
Bundles: Copy NuGet.Config and global.json files
Browse files Browse the repository at this point in the history
Fixes #25622, fixes #25483
  • Loading branch information
bricelam committed Sep 13, 2021
1 parent 0720568 commit abbcd1b
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions src/ef/Commands/MigrationsBundleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,56 @@ protected override int Execute(string[] args)
programGenerator.Initialize();

// TODO: We may not always have access to TEMP
var directory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(directory);
var tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(tempDirectory);
try
{
var directory = tempDirectory;

var globalJson = default(string);
var nugetConfigs = new Stack<string>();

var searchPath = WorkingDir!.Value();
do
{
foreach (var file in Directory.EnumerateFiles(searchPath))
{
var fileName = Path.GetFileName(file);
if (fileName.Equals("NuGet.Config", StringComparison.OrdinalIgnoreCase))
{
nugetConfigs.Push(file);
}
else if (globalJson == null
&& fileName.Equals("global.json", StringComparison.OrdinalIgnoreCase))
{
globalJson = file;
}
}

searchPath = Path.GetDirectoryName(searchPath);
}
while (searchPath != null);

while (nugetConfigs.Count > 1)
{
var nugetConfig = nugetConfigs.Pop();
File.Copy(nugetConfig, Path.Combine(directory, Path.GetFileName(nugetConfig)));

directory = Path.Combine(directory, Path.GetRandomFileName());
Directory.CreateDirectory(directory);
}

if (globalJson != null)
{
File.Copy(globalJson, Path.Combine(directory, Path.GetFileName(globalJson)));
}

if (nugetConfigs.Count > 0)
{
var nugetConfig = nugetConfigs.Pop();
File.Copy(nugetConfig, Path.Combine(directory, Path.GetFileName(nugetConfig)));
}

var publishArgs = new List<string> { "publish" };

var runtime = _runtime!.HasValue()
Expand Down Expand Up @@ -156,7 +202,7 @@ protected override int Execute(string[] args)
}
finally
{
Directory.Delete(directory, recursive: true);
Directory.Delete(tempDirectory, recursive: true);
}

return base.Execute(args);
Expand Down

0 comments on commit abbcd1b

Please sign in to comment.