Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 8fa0692

Browse files
committed
Generate repositories.config file after NuGet package restore.
The repositories.config contains a list of projects that share the packages directory. If this is not restored then uninstalling a NuGet package from one project could end up with NuGet removing it completely from the packages directory since it believes that no other project is referencing this NuGet package even if this is not the case.
1 parent f486456 commit 8fa0692

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

src/AddIns/Misc/PackageManagement/Project/Src/RestorePackagesCommand.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
using System;
2020
using System.IO;
21+
using System.Linq;
22+
using System.Threading.Tasks;
23+
2124
using ICSharpCode.Core;
2225
using ICSharpCode.SharpDevelop;
2326
using ICSharpCode.SharpDevelop.Gui;
@@ -71,7 +74,33 @@ void RunRestore()
7174

7275
var runner = new ProcessRunner();
7376
runner.WorkingDirectory = Path.GetDirectoryName(solution.FileName);
74-
runner.RunInOutputPadAsync(outputMessagesView.OutputCategory, commandLine.Command, commandLine.Arguments).FireAndForget();
77+
runner.RunInOutputPadAsync(outputMessagesView.OutputCategory, commandLine.Command, commandLine.Arguments)
78+
.ContinueWith(task => OnNuGetPackageRestoreComplete(task));
79+
}
80+
81+
void OnNuGetPackageRestoreComplete(Task<int> task)
82+
{
83+
if (task.Exception != null) {
84+
LoggingService.Debug(task.Exception.ToString());
85+
outputMessagesView.AppendLine(task.Exception.Message);
86+
} else {
87+
ForceGenerationOfRepositoriesConfigFile();
88+
}
89+
}
90+
91+
/// <summary>
92+
/// Create a Package Manager for each project to force a new repositories.config file
93+
/// to be generated with references to all projects that have NuGet packages.
94+
/// </summary>
95+
void ForceGenerationOfRepositoriesConfigFile()
96+
{
97+
try {
98+
var repository = PackageManagementServices.RegisteredPackageRepositories.CreateAggregateRepository();
99+
var projects = solution.GetProjects(repository).ToList();
100+
} catch (Exception ex) {
101+
LoggingService.Debug(ex.ToString());
102+
outputMessagesView.AppendLine(ex.Message);
103+
}
75104
}
76105
}
77106
}

0 commit comments

Comments
 (0)