Skip to content
Open
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 @@ -43,14 +43,14 @@ public class CpsPackageReferenceProject : PackageReferenceProject<List<Framework
private const string TargetFrameworkCondition = "TargetFramework";

private readonly IProjectSystemCache _projectSystemCache;
private readonly UnconfiguredProject _unconfiguredProject;
private readonly Microsoft.VisualStudio.Threading.AsyncLazy<UnconfiguredProject> _unconfiguredProject;

public CpsPackageReferenceProject(
string projectName,
string projectUniqueName,
string projectFullPath,
IProjectSystemCache projectSystemCache,
UnconfiguredProject unconfiguredProject,
Microsoft.VisualStudio.Threading.AsyncLazy<UnconfiguredProject> unconfiguredProject,
INuGetProjectServices projectServices,
string projectId)
: base(projectName,
Expand Down Expand Up @@ -269,7 +269,8 @@ public override async Task<bool> InstallPackageAsync(
{
// This is the "partial install" case. That is, install the package to only a subset of the frameworks
// supported by this project.
var conditionalService = _unconfiguredProject
var unconfiguredProject = await _unconfiguredProject.GetValueAsync(token);
var conditionalService = unconfiguredProject
.Services
.ExportProvider
.GetExportedValue<IConditionalPackageReferencesService>();
Expand Down Expand Up @@ -315,7 +316,8 @@ await SetPackagePropertyValueAsync(
else
{
// Install the package to all frameworks.
var configuredProject = await _unconfiguredProject.GetSuggestedConfiguredProjectAsync();
var unconfiguredProject = await _unconfiguredProject.GetValueAsync(token);
var configuredProject = await unconfiguredProject.GetSuggestedConfiguredProjectAsync();

var result = await configuredProject
.Services
Expand Down Expand Up @@ -367,7 +369,8 @@ public override async Task<bool> UninstallPackageAsync(string packageId, BuildIn

if (installationContext.SuccessfulFrameworks.Any() && installationContext.UnsuccessfulFrameworks.Any())
{
var conditionalService = _unconfiguredProject
var unconfiguredProject = await _unconfiguredProject.GetValueAsync(token);
var conditionalService = unconfiguredProject
.Services
.ExportProvider
.GetExportedValue<IConditionalPackageReferencesService>();
Expand All @@ -387,7 +390,8 @@ public override async Task<bool> UninstallPackageAsync(string packageId, BuildIn
}
else
{
var configuredProject = await _unconfiguredProject.GetSuggestedConfiguredProjectAsync();
var unconfiguredProject = await _unconfiguredProject.GetValueAsync(token);
var configuredProject = await unconfiguredProject.GetSuggestedConfiguredProjectAsync();

await configuredProject?.Services.PackageReferences.RemoveAsync(packageId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.VisualStudio.ProjectSystem;
using Microsoft.VisualStudio.ProjectSystem.Properties;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Threading;
using Microsoft.VisualStudio.Utilities;
using NuGet.ProjectManagement;
using NuGet.ProjectModel;
Expand Down Expand Up @@ -80,16 +81,21 @@ public NuGetProject TryCreateNuGetProject(
}

var fullProjectPath = vsProject.FullProjectPath;
var unconfiguredProject = GetUnconfiguredProject(vsProject.Project);

var projectServices = new CpsProjectSystemServices(vsProject, _scriptExecutor);

var lazyUnconfiguredProject = new AsyncLazy<UnconfiguredProject>(async () =>
{
await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
return GetUnconfiguredProject(vsProject.Project);
}, NuGetUIThreadHelper.JoinableTaskFactory);

return new CpsPackageReferenceProject(
vsProject.ProjectName,
vsProject.CustomUniqueName,
fullProjectPath,
_projectSystemCache,
unconfiguredProject,
lazyUnconfiguredProject,
projectServices,
vsProject.ProjectId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4421,7 +4421,6 @@ public async Task GetPackageSpecsAndAdditionalMessagesAsync_NoRestoreInfoInSolut
{
// Arrange
var projectSystemCache = new Mock<IProjectSystemCache>();
var unconfiguredProject = new Mock<UnconfiguredProject>();
var nugetProjectServices = new Mock<INuGetProjectServices>();
var projectGuid = Guid.NewGuid();
var cacheContext = new DependencyGraphCacheContext();
Expand All @@ -4432,7 +4431,7 @@ public async Task GetPackageSpecsAndAdditionalMessagesAsync_NoRestoreInfoInSolut
@"src\TestProject\TestProject.csproj",
@"c:\repo\src\TestProject\TestProject.csproj",
projectSystemCache.Object,
unconfiguredProject.Object,
null,
nugetProjectServices.Object,
projectGuid.ToString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(

Initialize(packageSources);

var unconfiguredProject = new Mock<UnconfiguredProject>();
var mockUnconfiguredProject = new Mock<UnconfiguredProject>();
var configuredProject = new Mock<ConfiguredProject>();
var projectServices = new Mock<ConfiguredProjectServices>();
var packageReferencesService = new Mock<IPackageReferencesService>();
var result = new Mock<IUnresolvedPackageReference>();

unconfiguredProject.Setup(x => x.GetSuggestedConfiguredProjectAsync())
mockUnconfiguredProject.Setup(x => x.GetSuggestedConfiguredProjectAsync())
.ReturnsAsync(configuredProject.Object);

configuredProject.SetupGet(x => x.Services)
Expand All @@ -175,6 +175,9 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageReferencesService.Setup(x => x.AddAsync(It.IsNotNull<string>(), It.IsNotNull<string>()))
.ReturnsAsync(new AddReferenceResult<IUnresolvedPackageReference>(result.Object, added: true));

var unconfiguredProject = new Microsoft.VisualStudio.Threading.AsyncLazy<UnconfiguredProject>(
() => Task.FromResult(mockUnconfiguredProject.Object));

var nuGetProjectServices = new Mock<INuGetProjectServices>();

nuGetProjectServices.SetupGet(x => x.ScriptService)
Expand All @@ -188,7 +191,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
projectUniqueName: projectFullPath,
projectFullPath: projectFullPath,
projectSystemCache,
unconfiguredProject.Object,
unconfiguredProject,
nuGetProjectServices.Object,
projectId);

Expand Down Expand Up @@ -429,13 +432,13 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(

Initialize(packageSources);

var unconfiguredProject = new Mock<UnconfiguredProject>();
var mockUnconfiguredProject = new Mock<UnconfiguredProject>();
var configuredProject = new Mock<ConfiguredProject>();
var projectServices = new Mock<ConfiguredProjectServices>();
var packageReferencesService = new Mock<IPackageReferencesService>();
var result = new Mock<IUnresolvedPackageReference>();

unconfiguredProject.Setup(x => x.GetSuggestedConfiguredProjectAsync())
mockUnconfiguredProject.Setup(x => x.GetSuggestedConfiguredProjectAsync())
.ReturnsAsync(configuredProject.Object);

configuredProject.SetupGet(x => x.Services)
Expand All @@ -447,6 +450,9 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageReferencesService.Setup(x => x.AddAsync(It.IsNotNull<string>(), It.IsNotNull<string>()))
.ReturnsAsync(new AddReferenceResult<IUnresolvedPackageReference>(result.Object, added: true));

var unconfiguredProject = new Microsoft.VisualStudio.Threading.AsyncLazy<UnconfiguredProject>(
() => Task.FromResult(mockUnconfiguredProject.Object));

var nuGetProjectServices = new Mock<INuGetProjectServices>();

nuGetProjectServices.SetupGet(x => x.ScriptService)
Expand All @@ -460,7 +466,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
projectUniqueName: projectFullPath,
projectFullPath: projectFullPath,
projectSystemCache,
unconfiguredProject.Object,
unconfiguredProject,
nuGetProjectServices.Object,
projectId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private TestCpsPackageReferenceProject(
string projectUniqueName,
string projectFullPath,
IProjectSystemCache projectSystemCache,
UnconfiguredProject unconfiguredProject,
Microsoft.VisualStudio.Threading.AsyncLazy<UnconfiguredProject> unconfiguredProject,
INuGetProjectServices projectServices,
string projectId,
string assetsFilePath,
Expand Down
Loading