Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundles: Copy NuGet.Config and global.json files #26005

Merged
merged 1 commit into from
Sep 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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