diff options
author | Matt Ward <matt.ward@microsoft.com> | 2019-10-01 19:20:27 +0300 |
---|---|---|
committer | monojenkins <jo.shields+jenkins@xamarin.com> | 2019-10-21 19:40:01 +0300 |
commit | 46ca51e0eb455c92d63bc4c21aac6d8567549eba (patch) | |
tree | 9beb9fbb8544eb483f0498833cc538e717c6b483 /main/src/addins/MonoDevelop.PackageManagement | |
parent | b01f3bc487c086aae229c4a35c3a67e839b4902b (diff) |
[NuGet] Fix projects not being re-evaluated after packages updated
Updating a package for multiple projects in one step results in the
NuGet package restore that is done at the end being a no-op. This
means that the project is not re-evaluated which can mean that the
AvailableItemNames are not updated. Updating a single NuGet package
does not have the same problem.
Also fixed a problem where a PackageReference project (non-sdk) was
not re-evaluated on restoring. This could also result in the
AvailableItemNames not being available to the project if the project
was missing its obj/project.assets.json file on being opened in the
IDE.
Diffstat (limited to 'main/src/addins/MonoDevelop.PackageManagement')
3 files changed, 117 insertions, 1 deletions
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/InstallPackageWithAvailableItemNameTests.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/InstallPackageWithAvailableItemNameTests.cs index c32ec699b7..fcc15da5b8 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/InstallPackageWithAvailableItemNameTests.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/InstallPackageWithAvailableItemNameTests.cs @@ -28,6 +28,7 @@ using System.Linq; using System.Threading.Tasks; using MonoDevelop.PackageManagement.Tests.Helpers; using MonoDevelop.Projects; +using NuGet.Packaging.Core; using NuGet.Versioning; using NUnit.Framework; using UnitTests; @@ -54,6 +55,72 @@ namespace MonoDevelop.PackageManagement.Tests } } + [Test] + public async Task UpdatePackage_PackageDefinesCustomAvailableItemNames_BuildActionsIncludeUpdateAvailableItemNames () + { + string solutionFileName = Util.GetSampleProject ("NuGetUpdateAvailableItems", "NuGetUpdateAvailableItems.sln"); + using (solution = (Solution)await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solutionFileName)) { + CreateNuGetConfigFile (solution.BaseDirectory); + await RestoreNuGetPackages (solution); + var packageReferenceProject = (DotNetProject)solution.FindProjectByName ("PackageReferenceProject"); + var sdkStyleProject = (DotNetProject)solution.FindProjectByName ("SdkStyleProject"); + + var originalBuildActions = packageReferenceProject.GetBuildActions (); + + Assert.That (originalBuildActions, Contains.Item ("TestXamAvailableItem")); + Assert.IsFalse (originalBuildActions.Contains ("TestXamAvailableItemUpdated")); + + originalBuildActions = sdkStyleProject.GetBuildActions (); + + Assert.That (originalBuildActions, Contains.Item ("TestXamAvailableItem")); + Assert.IsFalse (originalBuildActions.Contains ("TestXamAvailableItemUpdated")); + + await UpdateNuGetPackage (packageReferenceProject, "Test.Xam.AvailableItemName"); + await UpdateNuGetPackage (sdkStyleProject, "Test.Xam.AvailableItemName"); + + var updatedBuildActions = packageReferenceProject.GetBuildActions (); + + Assert.That (updatedBuildActions, Contains.Item ("TestXamAvailableItemUpdated")); + + updatedBuildActions = sdkStyleProject.GetBuildActions (); + + Assert.That (updatedBuildActions, Contains.Item ("TestXamAvailableItemUpdated")); + } + } + + [Test] + public async Task UpdateMultiplePackages_PackageDefinesCustomAvailableItemNames_BuildActionsIncludeUpdateAvailableItemNames () + { + string solutionFileName = Util.GetSampleProject ("NuGetUpdateAvailableItems", "NuGetUpdateAvailableItems.sln"); + using (solution = (Solution)await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solutionFileName)) { + CreateNuGetConfigFile (solution.BaseDirectory); + await RestoreNuGetPackages (solution); + var packageReferenceProject = (DotNetProject)solution.FindProjectByName ("PackageReferenceProject"); + var sdkStyleProject = (DotNetProject)solution.FindProjectByName ("SdkStyleProject"); + + var originalBuildActions = packageReferenceProject.GetBuildActions (); + + Assert.That (originalBuildActions, Contains.Item ("TestXamAvailableItem")); + Assert.IsFalse (originalBuildActions.Contains ("TestXamAvailableItemUpdated")); + + originalBuildActions = sdkStyleProject.GetBuildActions (); + + Assert.That (originalBuildActions, Contains.Item ("TestXamAvailableItem")); + Assert.IsFalse (originalBuildActions.Contains ("TestXamAvailableItemUpdated")); + + var projects = new [] { packageReferenceProject, sdkStyleProject }; + await UpdateNuGetPackage (projects, "Test.Xam.AvailableItemName", "0.2.0"); + + var updatedBuildActions = packageReferenceProject.GetBuildActions (); + + Assert.That (updatedBuildActions, Contains.Item ("TestXamAvailableItemUpdated")); + + updatedBuildActions = sdkStyleProject.GetBuildActions (); + + Assert.That (updatedBuildActions, Contains.Item ("TestXamAvailableItemUpdated")); + } + } + Task InstallNuGetPackage (DotNetProject project, string packageId, string packageVersion) { var solutionManager = new MonoDevelopSolutionManager (project.ParentSolution); @@ -70,5 +137,46 @@ namespace MonoDevelop.PackageManagement.Tests action.Execute (); }); } + + Task UpdateNuGetPackage (DotNetProject project, string packageId) + { + var solutionManager = new MonoDevelopSolutionManager (project.ParentSolution); + var context = CreateNuGetProjectContext (solutionManager.Settings); + var packageManager = new MonoDevelopNuGetPackageManager (solutionManager); + + var action = new UpdateNuGetPackageAction ( + solutionManager, + new DotNetProjectProxy (project), + context, + packageManager, + PackageManagementServices.PackageManagementEvents) { + PackageId = packageId + }; + + return Task.Run (() => { + action.Execute (); + }); + } + + Task UpdateNuGetPackage (DotNetProject[] projects, string packageId, string packageVersion) + { + var solutionManager = new MonoDevelopSolutionManager (projects [0].ParentSolution); + var context = CreateNuGetProjectContext (solutionManager.Settings); + var sources = solutionManager.CreateSourceRepositoryProvider ().GetRepositories (); + + var action = new UpdateMultipleNuGetPackagesAction (sources, solutionManager, context); + action.LicensesMustBeAccepted = false; + + foreach (DotNetProject project in projects) { + action.AddProject (new DotNetProjectProxy (project)); + } + + var packageIdentity = new PackageIdentity (packageId, NuGetVersion.Parse (packageVersion)); + action.AddPackageToUpdate (packageIdentity); + + return Task.Run (() => { + action.Execute (); + }); + } } } diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopBuildIntegratedRestorer.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopBuildIntegratedRestorer.cs index ffffaa7c60..e84a31911c 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopBuildIntegratedRestorer.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopBuildIntegratedRestorer.cs @@ -250,6 +250,10 @@ namespace MonoDevelop.PackageManagement if (dotNetCoreNuGetProject?.ProjectRequiresReloadAfterRestore () == true)
return dotNetCoreNuGetProject.DotNetProject;
+ var packageReferenceNuGetProject = project as PackageReferenceNuGetProject;
+ if (packageReferenceNuGetProject?.ProjectRequiresReloadAfterRestore () == true)
+ return packageReferenceNuGetProject.DotNetProject;
+
return null;
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopNuGetPackageManager.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopNuGetPackageManager.cs index 336fcd6c3e..6c2ad61cb4 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopNuGetPackageManager.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopNuGetPackageManager.cs @@ -351,8 +351,12 @@ namespace MonoDevelop.PackageManagement dotNetProject.DotNetProject.ShutdownProjectBuilder (); if (!packageRestorer.LockFileChanged) { + // Need to re-evaluate. When updating multiple projects the restore done at the end + // may be a no-op. This results in no re-evaluation being done so we re-evaluate here. + // // Need to refresh the references since the restore did not. - await Runtime.RunInMainThread (() => { + await Runtime.RunInMainThread (async () => { + await dotNetProject.DotNetProject.ReevaluateProject (new ProgressMonitor ()); dotNetProject.DotNetProject.DotNetCoreNotifyReferencesChanged (); }); } |