diff options
author | Matt Ward <matt.ward@microsoft.com> | 2019-03-05 17:41:37 +0300 |
---|---|---|
committer | monojenkins <jo.shields+jenkins@xamarin.com> | 2019-03-06 16:32:27 +0300 |
commit | 093059943497345ee681ad36597bc45c968354bd (patch) | |
tree | e11fc5531cb34db1146022d280a10b36929f4aa9 /main | |
parent | 72efd06d586dbe36d20d1b88e53a290bebc5b290 (diff) |
[NuGet] Raise install/uninstall events for PackageReference projects
The NuGet addin API has a PackageReferenceAdded event and a
PackageReferenceRemoved. These were being raised if a project had
a packages.config file but not if the project used PackageReferences.
Fixes VSTS #807927 - Get the events working for an Android project
that uses PackageReferences
Diffstat (limited to 'main')
2 files changed, 54 insertions, 3 deletions
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/PackageReferenceNuGetProjectTests.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/PackageReferenceNuGetProjectTests.cs index 2167100d23..23aaedc1fa 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/PackageReferenceNuGetProjectTests.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/PackageReferenceNuGetProjectTests.cs @@ -24,12 +24,14 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using MonoDevelop.Core; using MonoDevelop.PackageManagement.Tests.Helpers; using MonoDevelop.Projects; +using NuGet.PackageManagement; using NuGet.Packaging.Core; using NuGet.ProjectManagement; using NuGet.ProjectModel; @@ -388,5 +390,45 @@ namespace MonoDevelop.PackageManagement.Tests int projectItemsCount = dotNetProject.Files.Count; Assert.AreEqual (1, projectItemsCount); } + + [Test] + public void OnAfterExecuteActions_PackageInstallAction_PackageInstalledEventFired () + { + CreateNuGetProject (); + var packageIdentity = new PackageIdentity ("Test", NuGetVersion.Parse ("1.2")); + var actions = new List<NuGetProjectAction> (); + var action = NuGetProjectAction.CreateInstallProjectAction (packageIdentity, null, project); + actions.Add (action); + PackageManagementEventArgs eventArgs = null; + project.PackageManagementEvents.PackageInstalled += (sender, e) => { + eventArgs = e; + }; + + project.OnAfterExecuteActions (actions); + + Assert.AreEqual ("Test", eventArgs.Id); + Assert.AreEqual ("1.2", eventArgs.Version.ToString ()); + Assert.AreEqual (packageIdentity, eventArgs.Package); + } + + [Test] + public void OnAfterExecuteActions_PackageUninstallAction_PackageUninstalledEventFired () + { + CreateNuGetProject (); + var packageIdentity = new PackageIdentity ("Test", NuGetVersion.Parse ("1.2")); + var actions = new List<NuGetProjectAction> (); + var action = NuGetProjectAction.CreateUninstallProjectAction (packageIdentity, project); + actions.Add (action); + PackageManagementEventArgs eventArgs = null; + project.PackageManagementEvents.PackageUninstalled += (sender, e) => { + eventArgs = e; + }; + + project.OnAfterExecuteActions (actions); + + Assert.AreEqual ("Test", eventArgs.Id); + Assert.AreEqual ("1.2", eventArgs.Version.ToString ()); + Assert.AreEqual (packageIdentity, eventArgs.Package); + } } } diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageReferenceNuGetProject.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageReferenceNuGetProject.cs index e755b501bb..4892485906 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageReferenceNuGetProject.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageReferenceNuGetProject.cs @@ -51,20 +51,20 @@ namespace MonoDevelop.PackageManagement { DotNetProject project; ConfigurationSelector configuration; - IPackageManagementEvents packageManagementEvents; + PackageManagementEvents packageManagementEvents; string msbuildProjectPath; string projectName; bool reevaluationRequired; public PackageReferenceNuGetProject (DotNetProject project, ConfigurationSelector configuration) - : this (project, configuration, PackageManagementServices.PackageManagementEvents) + : this (project, configuration, (PackageManagementEvents)PackageManagementServices.PackageManagementEvents) { } public PackageReferenceNuGetProject ( DotNetProject project, ConfigurationSelector configuration, - IPackageManagementEvents packageManagementEvents) + PackageManagementEvents packageManagementEvents) { this.project = project; this.configuration = configuration; @@ -261,6 +261,15 @@ namespace MonoDevelop.PackageManagement public void OnAfterExecuteActions (IEnumerable<NuGetProjectAction> actions) { reevaluationRequired = actions.Any (action => action.NuGetProjectActionType == NuGetProjectActionType.Install); + + foreach (var action in actions) { + var eventArgs = new PackageEventArgs (this, action.PackageIdentity, null); + if (action.NuGetProjectActionType == NuGetProjectActionType.Install) { + packageManagementEvents.OnPackageInstalled (Project, eventArgs); + } else if (action.NuGetProjectActionType == NuGetProjectActionType.Uninstall) { + packageManagementEvents.OnPackageUninstalled (Project, eventArgs); + } + } } public void NotifyProjectReferencesChanged (bool includeTransitiveProjectReferences) |