diff options
author | Greg Munn <gregm@microsoft.com> | 2019-10-01 18:33:23 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-01 18:33:23 +0300 |
commit | 8be262f12405bcf8613e19a8e6afc22dcbeee7be (patch) | |
tree | f76ecae2220e392e5b3da3be8148782feff41bf1 /main/src/addins/MonoDevelop.PackageManagement | |
parent | 709985d57b09d0ec4d54cad27428d5a84901a8bc (diff) | |
parent | 0e9e1d3f02845c38aedd97ccbbe67d2c8c9f99fb (diff) |
Merge pull request #8804 from mono/nuget-null-reference-getting-package-reference-info
[NuGet] Handle NuGet addin API used when project disposed
Diffstat (limited to 'main/src/addins/MonoDevelop.PackageManagement')
2 files changed, 24 insertions, 1 deletions
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/ProjectPackageReferenceTests.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/ProjectPackageReferenceTests.cs index aa0919198d..c81165e087 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/ProjectPackageReferenceTests.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/ProjectPackageReferenceTests.cs @@ -27,6 +27,7 @@ using System; using System.Xml; using MonoDevelop.PackageManagement.Tests.Helpers; +using MonoDevelop.Projects; using MonoDevelop.Projects.MSBuild; using NUnit.Framework; @@ -98,5 +99,26 @@ namespace MonoDevelop.PackageManagement.Tests Assert.IsFalse (packageReference.HasAllowedVersions); Assert.IsFalse (projectPackageReference.IsAtLeastVersion (new Version (3, 1))); } + + /// <summary> + /// Ensure that a null MSBuildProject does not break getting a PackageReference. + /// Previously this would throw a null reference exception when an attempt was made + /// to determine the frameworks defined by the project. + /// </summary> + [Test] + public void DisposedProject () + { + var project = Services.ProjectService.CreateDotNetProject ("C#"); + var projectPackageReference = ProjectPackageReference.Create ("Test", "1.2.3"); + project.Items.Add (projectPackageReference); + + project.Dispose (); + + var packageReference = projectPackageReference.CreatePackageReference (); + + Assert.IsNull (project.MSBuildProject); + Assert.AreEqual ("Test", packageReference.PackageIdentity.Id); + Assert.AreEqual ("1.2.3", packageReference.PackageIdentity.Version.ToString ()); + } } } diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectExtensions.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectExtensions.cs index 1954713237..e8eef1af58 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectExtensions.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectExtensions.cs @@ -156,7 +156,8 @@ namespace MonoDevelop.PackageManagement public static IEnumerable<string> GetDotNetCoreTargetFrameworks (this Project project)
{
- foreach (MSBuildPropertyGroup propertyGroup in project.MSBuildProject.PropertyGroups) {
+ var groups = project.MSBuildProject?.PropertyGroups ?? Enumerable.Empty<MSBuildPropertyGroup> ();
+ foreach (MSBuildPropertyGroup propertyGroup in groups) {
string framework = propertyGroup.GetValue ("TargetFramework", null);
if (framework != null)
return new [] { framework };
|