Skip to content
Merged
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 @@ -331,6 +331,8 @@ private static bool IsRestoredOnSolutionLoad(NuGetProject nuGetProject)
return false;
}

public CancellationToken VsShutdownToken => VsShellUtilities.ShutdownToken;

/// <summary>
/// IsSolutionOpen is true, if the dte solution is open
/// and is saved as required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Threading;
using NuGet.Configuration;
using NuGet.Credentials;
Expand All @@ -20,15 +19,12 @@ namespace NuGet.PackageManagement.VisualStudio
public class VsCredentialProviderAdapter : ICredentialProvider
{
private readonly IVsCredentialProvider _provider;
private readonly IVsSolutionManager _solutionManager;

public VsCredentialProviderAdapter(IVsCredentialProvider provider)
public VsCredentialProviderAdapter(IVsCredentialProvider provider, IVsSolutionManager solutionManager)
{
if (provider == null)
{
throw new ArgumentNullException(nameof(provider));
}

_provider = provider;
_provider = provider ?? throw new ArgumentNullException(nameof(provider));
_solutionManager = solutionManager ?? throw new ArgumentNullException(nameof(solutionManager));
}

public string Id => _provider.GetType().FullName;
Expand Down Expand Up @@ -59,7 +55,7 @@ public async Task<CredentialResponse> GetAsync(
isProxyRequest: type == CredentialRequestType.Proxy,
isRetry: isRetry,
nonInteractive: nonInteractive,
cancellationToken: VsShellUtilities.ShutdownToken);
cancellationToken: _solutionManager.VsShutdownToken);

// Since the above task will only cancel when VS is shutting down, we can abandon the task when our own cancellation token
// requests cancellation and we're not in interactive mode. This lets us free resources (like concurrent requests per host limits)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public VsCredentialProviderImporter(
[ImportMany(typeof(IVsCredentialProvider))]
public IEnumerable<Lazy<IVsCredentialProvider>> ImportedProviders { get; set; }

[Import]
public IVsSolutionManager SolutionManager { get; set; }

/// <summary>
/// Plugin providers are entered loaded the same way as other nuget extensions,
/// matching any extension named CredentialProvider.*.exe.
Expand Down Expand Up @@ -88,7 +91,7 @@ private void TryImportCredentialProviders(
try
{
var credentialProvider = credentialProviderFactory.Value;
importedProviders.Add(new VsCredentialProviderAdapter(credentialProvider));
importedProviders.Add(new VsCredentialProviderAdapter(credentialProvider, SolutionManager));
}
catch (Exception exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using NuGet.ProjectManagement;
using NuGet.VisualStudio;
Expand Down Expand Up @@ -101,5 +102,8 @@ public interface IVsSolutionManager : ISolutionManager
/// Gets the current open solution directory. <see cref="null"/> if the there's no open solution.
/// </summary>
Task<string> GetSolutionDirectoryAsync();

/// <summary>Mockable indirection for <see cref="Microsoft.VisualStudio.Shell.VsShellUtilities.ShutdownToken"/></summary>
CancellationToken VsShutdownToken { get; }
}
}
3 changes: 2 additions & 1 deletion test/EndToEnd/tests/InstallPackageTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ function Test-AddBindingRedirectToWebsiteWithNonExistingOutputPath {
}

function Test-InstallCanPipeToFSharpProjects {
param($context)
[SkipTest('https://github.com/NuGet/Home/issues/11982')]
param($context)
# Arrange
$p = New-FSharpLibrary
Build-Solution # wait for project nomination
Expand Down
1 change: 1 addition & 0 deletions test/EndToEnd/tests/UninstallPackageTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ function Test-UninstallPackageWithNestedContentFiles {
}

function Test-SimpleFSharpUninstall {
[SkipTest('https://github.com/NuGet/Home/issues/11982')]
param($context)

# Arrange
Expand Down
5 changes: 2 additions & 3 deletions test/EndToEnd/tests/UpdatePackageTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,8 @@ function Test-UpdateAllPackagesInSolution {
}

function Test-UpdatePackageOnAnFSharpProjectWithMultiplePackages {
param(
$context
)
[SkipTest('https://github.com/NuGet/Home/issues/11982')]
param($context)

# Arrange
$p = New-FSharpLibrary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,8 @@ private sealed class TestVsSolutionManager : IVsSolutionManager, IDisposable

public string SolutionDirectory => _directory.Path;

public CancellationToken VsShutdownToken => CancellationToken.None;

public bool IsSolutionOpen => throw new NotImplementedException();

public INuGetProjectContext NuGetProjectContext { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Moq;
using NuGet.Configuration;
using NuGet.Credentials;
using NuGet.VisualStudio;
Expand All @@ -14,6 +15,15 @@ namespace NuGet.PackageManagement.VisualStudio.Test
{
public class VsCredentialProviderAdapterTests
{
private Mock<IVsSolutionManager> _solutionManager;

public VsCredentialProviderAdapterTests()
{
_solutionManager = new Mock<IVsSolutionManager>();
_solutionManager.SetupGet(sm => sm.VsShutdownToken)
.Returns(CancellationToken.None);
}

private class TestVsCredentialProvider : IVsCredentialProvider
{
private readonly ICredentials _testResponse;
Expand All @@ -35,7 +45,7 @@ public async Task WhenCredsNull_ThenReturnProviderNotApplicable()
{
// Arrange
var provider = new TestVsCredentialProvider(null);
var adapter = new VsCredentialProviderAdapter(provider);
var adapter = new VsCredentialProviderAdapter(provider, _solutionManager.Object);

// Act
var result = await adapter.GetAsync(
Expand All @@ -58,7 +68,7 @@ public async Task WhenAnyValidVsCredentialResponse_Ok()
// Arrange
var expected = new NetworkCredential("foo", "bar");
var provider = new TestVsCredentialProvider(expected);
var adapter = new VsCredentialProviderAdapter(provider);
var adapter = new VsCredentialProviderAdapter(provider, _solutionManager.Object);

// Act
var result = await adapter.GetAsync(
Expand Down