Skip to content
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
[assembly: SuppressMessage("Build", "CA1303:Method 'Task SolutionRestoreWorker.PromoteTaskToActiveAsync(BackgroundRestoreOperation restoreOperation, CancellationToken token)' passes a literal string as parameter 'message' of a call to 'InvalidOperationException.InvalidOperationException(string message)'. Retrieve the following string(s) from a resource table instead: \"Failed promoting pending task.\".", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.SolutionRestoreManager.SolutionRestoreWorker.PromoteTaskToActiveAsync(NuGet.SolutionRestoreManager.SolutionRestoreWorker.BackgroundRestoreOperation,System.Threading.CancellationToken)~System.Threading.Tasks.Task")]
[assembly: SuppressMessage("Build", "CA1031:Modify 'ScheduleRestoreAsync' to catch a more specific allowed exception type, or rethrow the exception.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.SolutionRestoreManager.SolutionRestoreWorker.ScheduleRestoreAsync(NuGet.VisualStudio.SolutionRestoreRequest,System.Threading.CancellationToken)~System.Threading.Tasks.Task{System.Boolean}")]
[assembly: SuppressMessage("Build", "CA1031:Modify 'StartBackgroundJobRunnerAsync' to catch a more specific allowed exception type, or rethrow the exception.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.SolutionRestoreManager.SolutionRestoreWorker.StartBackgroundJobRunnerAsync(System.Threading.CancellationToken)~System.Threading.Tasks.Task{System.Boolean}")]
[assembly: SuppressMessage("Build", "CA1031:Modify 'NotifyWaitingForBackgroundRestoreAsync' to catch a more specific allowed exception type, or rethrow the exception.", Justification = "Informational notification; must never fail the calling restore/build path.", Scope = "member", Target = "~M:NuGet.SolutionRestoreManager.SolutionRestoreWorker.NotifyWaitingForBackgroundRestoreAsync~System.Threading.Tasks.Task")]
[assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.SolutionRestoreManager.SolutionRestoreJob.ExecuteAsync(NuGet.VisualStudio.SolutionRestoreRequest,NuGet.PackageManagement.VisualStudio.SolutionRestoreJobContext,NuGet.SolutionRestoreManager.RestoreOperationLogger,System.Collections.Generic.Dictionary{System.String,System.Object},System.Lazy{NuGet.SolutionRestoreManager.IVulnerabilitiesNotificationService},System.Threading.CancellationToken)~System.Threading.Tasks.Task{System.Boolean}")]
[assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.SolutionRestoreManager.VsRestoreProgressEvents.EndProjectUpdate(System.String,System.Collections.Generic.IReadOnlyList{System.String})")]
[assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.SolutionRestoreManager.VsRestoreProgressEvents.EndSolutionRestore(System.Collections.Generic.IReadOnlyList{System.String})")]
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,8 @@ To prevent NuGet from restoring packages during build, open the Visual Studio Op
<value>Fix with GitHub Copilot</value>
<comment>Do not translate GitHub or Copilot</comment>
</data>
<data name="WaitingForBackgroundRestore" xml:space="preserve">
<value>Waiting for NuGet package restore to finish before building...</value>
<comment>Shown in the Build output window when a build is blocked on an already-running background NuGet restore.</comment>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,38 @@ public async Task<bool> RestoreAsync(SolutionRestoreRequest request, Cancellatio

using (var restoreOperation = new BackgroundRestoreOperation())
{
// If a background restore is already running, the caller (typically a build)
// would otherwise sit silently until that restore completes. Surface a hint
// in the Build output window so the user knows why the build is paused.
if (IsBusy && request.RestoreSource == RestoreOperationSource.OnBuild)
{
await NotifyWaitingForBackgroundRestoreAsync();

// Ride on the in-flight restore instead of queuing another one behind it,
// unless the build explicitly asked for a forced restore.
if (!request.ForceRestore)
{
Task<bool> inflight = _activeRestoreTask;
bool inflightSucceeded = await inflight.WithCancellation(token);
if (inflightSucceeded)
{
bool queueEmpty;
lock (_lockPendingRequestsObj)
{
// If there are no pending requests and _activeRestoreTask is the same one we awaited, then we have a valid restore for the purpose of build.
// If the tasks *don't* match, it means another restore has been kicked off since we awaited, so we should queue a new restore to be safe.
// This case should be rare.
queueEmpty = _pendingRequests.Value.Count == 0 && ReferenceEquals(_activeRestoreTask, inflight);
}

if (queueEmpty)
{
return true;
}
}
}
}

await PromoteTaskToActiveAsync(restoreOperation, token);
var restoreTrackingData = GetRestoreTrackingData(
restoreReason: ImplicitRestoreReason.None,
Expand Down Expand Up @@ -714,6 +746,21 @@ private async Task<bool> ProcessRestoreRequestAsync(
return restoreTask;
}

private async Task NotifyWaitingForBackgroundRestoreAsync()
{
try
{
IOutputConsole buildConsole = await _outputConsoleProvider.Value.CreateBuildOutputConsoleAsync();
await buildConsole.ActivateAsync();
await buildConsole.WriteLineAsync(Resources.WaitingForBackgroundRestore);
}
catch (Exception ex)
{
// Notification is informational; never let it fail the restore/build path.
Logger.LogError(ex.ToString());
}
}

private async Task PromoteTaskToActiveAsync(BackgroundRestoreOperation restoreOperation, CancellationToken token)
{
var pendingTask = restoreOperation.Task;
Expand All @@ -726,13 +773,19 @@ private async Task PromoteTaskToActiveAsync(BackgroundRestoreOperation restoreOp
// Grab local copy of active task
var activeTask = _activeRestoreTask;

// Await for the completion of the active *unbound* task
var cancelTcs = new TaskCompletionSource<bool>();
// Await for the completion of the active *unbound* task.
// Use RunContinuationsAsynchronously so cancellation callbacks don't run
// the continuation inline on the thread that triggered the cancellation.
var cancelTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
using (var ctr = token.Register(() => cancelTcs.TrySetCanceled()))
{
await Task.WhenAny(activeTask, cancelTcs.Task);
}

// If the wait ended because of cancellation, surface it to the caller
// instead of silently leaving _activeRestoreTask unchanged.
token.ThrowIfCancellationRequested();

// Try replacing active task with the new one.
// Retry from the beginning if the active task has changed.
retry = Interlocked.CompareExchange(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ Když nechcete, aby aplikace NuGet obnovovala balíčky během vytváření sest
<target state="translated">Řešení není uložené. Než začnete spravovat balíčky NuGet, řešení uložte.</target>
<note />
</trans-unit>
<trans-unit id="WaitingForBackgroundRestore">
<source>Waiting for NuGet package restore to finish before building...</source>
<target state="new">Waiting for NuGet package restore to finish before building...</target>
<note>Shown in the Build output window when a build is blocked on an already-running background NuGet restore.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ Wenn Sie verhindern möchten, dass NuGet Pakete während des Builds wiederherste
<target state="translated">Die Projektmappe wurde nicht gespeichert. Bitte speichern Sie Ihre Projektmappe, bevor Sie NuGet-Pakete verwalten.</target>
<note />
</trans-unit>
<trans-unit id="WaitingForBackgroundRestore">
<source>Waiting for NuGet package restore to finish before building...</source>
<target state="new">Waiting for NuGet package restore to finish before building...</target>
<note>Shown in the Build output window when a build is blocked on an already-running background NuGet restore.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ Para evitar que NuGet restaure paquetes durante la compilación, abra el cuadro
<target state="translated">No se guardó la solución. Guarde la solución antes de administrar los paquetes NuGet.</target>
<note />
</trans-unit>
<trans-unit id="WaitingForBackgroundRestore">
<source>Waiting for NuGet package restore to finish before building...</source>
<target state="new">Waiting for NuGet package restore to finish before building...</target>
<note>Shown in the Build output window when a build is blocked on an already-running background NuGet restore.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ Pour empêcher NuGet de restaurer les packages lors de la génération, ouvrez l
<target state="translated">La solution n'est pas enregistrée. Enregistrez votre solution avant de gérer des packages NuGet.</target>
<note />
</trans-unit>
<trans-unit id="WaitingForBackgroundRestore">
<source>Waiting for NuGet package restore to finish before building...</source>
<target state="new">Waiting for NuGet package restore to finish before building...</target>
<note>Shown in the Build output window when a build is blocked on an already-running background NuGet restore.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ Per impedire che NuGet ripristini i pacchetti durante la compilazione, aprire la
<target state="translated">Soluzione non salvata. Salvarla prima di gestire i pacchetti NuGet.</target>
<note />
</trans-unit>
<trans-unit id="WaitingForBackgroundRestore">
<source>Waiting for NuGet package restore to finish before building...</source>
<target state="new">Waiting for NuGet package restore to finish before building...</target>
<note>Shown in the Build output window when a build is blocked on an already-running background NuGet restore.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ NuGet がビルド中にパッケージを復元しないようにするには
<target state="translated">ソリューションが保存されていません。ソリューションを保存してから NuGet パッケージを管理してください。</target>
<note />
</trans-unit>
<trans-unit id="WaitingForBackgroundRestore">
<source>Waiting for NuGet package restore to finish before building...</source>
<target state="new">Waiting for NuGet package restore to finish before building...</target>
<note>Shown in the Build output window when a build is blocked on an already-running background NuGet restore.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ To prevent NuGet from restoring packages during build, open the Visual Studio Op
<target state="translated">솔루션이 저장되지 않았습니다. NuGet 패키지를 관리하려면 솔루션을 저장하십시오.</target>
<note />
</trans-unit>
<trans-unit id="WaitingForBackgroundRestore">
<source>Waiting for NuGet package restore to finish before building...</source>
<target state="new">Waiting for NuGet package restore to finish before building...</target>
<note>Shown in the Build output window when a build is blocked on an already-running background NuGet restore.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ Aby uniemożliwić narzędziu NuGet przywracanie pakietów podczas kompilacji, o
<target state="translated">Nie zapisano rozwiązania. Zapisz rozwiązanie zanim zaczniesz zarządzać pakietami NuGet.</target>
<note />
</trans-unit>
<trans-unit id="WaitingForBackgroundRestore">
<source>Waiting for NuGet package restore to finish before building...</source>
<target state="new">Waiting for NuGet package restore to finish before building...</target>
<note>Shown in the Build output window when a build is blocked on an already-running background NuGet restore.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ Para impedir que o NuGet restaure pacotes durante o build, abra a caixa de diál
<target state="translated">A solução não está salva. Salve sua solução antes de gerenciar os pacotes NuGet.</target>
<note />
</trans-unit>
<trans-unit id="WaitingForBackgroundRestore">
<source>Waiting for NuGet package restore to finish before building...</source>
<target state="new">Waiting for NuGet package restore to finish before building...</target>
<note>Shown in the Build output window when a build is blocked on an already-running background NuGet restore.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ To prevent NuGet from restoring packages during build, open the Visual Studio Op
<target state="translated">Решение не сохранено. Сохраните свое решение, прежде чем управлять пакетами NuGet.</target>
<note />
</trans-unit>
<trans-unit id="WaitingForBackgroundRestore">
<source>Waiting for NuGet package restore to finish before building...</source>
<target state="new">Waiting for NuGet package restore to finish before building...</target>
<note>Shown in the Build output window when a build is blocked on an already-running background NuGet restore.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ NuGet'in derleme sırasında paketleri geri yüklemesini önlemek için Visual S
<target state="translated">Çözüm kaydedilmedi. Lütfen NuGet paketlerini yönetmeden önce çözümünüzü kaydedin.</target>
<note />
</trans-unit>
<trans-unit id="WaitingForBackgroundRestore">
<source>Waiting for NuGet package restore to finish before building...</source>
<target state="new">Waiting for NuGet package restore to finish before building...</target>
<note>Shown in the Build output window when a build is blocked on an already-running background NuGet restore.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ To prevent NuGet from restoring packages during build, open the Visual Studio Op
<target state="translated">解决方案未保存。请先保存你的解决方案,然后再管理 NuGet 包。</target>
<note />
</trans-unit>
<trans-unit id="WaitingForBackgroundRestore">
<source>Waiting for NuGet package restore to finish before building...</source>
<target state="new">Waiting for NuGet package restore to finish before building...</target>
<note>Shown in the Build output window when a build is blocked on an already-running background NuGet restore.</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ To prevent NuGet from restoring packages during build, open the Visual Studio Op
<target state="translated">未儲存解決方案。請先儲存解決方案,再管理 NuGet 套件。</target>
<note />
</trans-unit>
<trans-unit id="WaitingForBackgroundRestore">
<source>Waiting for NuGet package restore to finish before building...</source>
<target state="new">Waiting for NuGet package restore to finish before building...</target>
<note>Shown in the Build output window when a build is blocked on an already-running background NuGet restore.</note>
</trans-unit>
</body>
</file>
</xliff>
Loading