Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorMatt Ward <matt.ward@xamarin.com>2016-03-18 20:03:27 +0300
committerMatt Ward <matt.ward@xamarin.com>2016-03-21 18:18:20 +0300
commit569d5e819fa015b45876f61c1c574f8a4b1070cf (patch)
treef95daa74cae132096f692967d21104dbb9be5b1e /main
parentd439fb4108ecbe220b382207a2c5d739b37dae8a (diff)
[NuGet] Insert MSBuild property files ( .props) at start of project.
Fixed bug #19054 - NuGet package MSBuild property files (.props) should be added to the start of the project file Installing a NuGet package that included an MSBuild .props file would add an Import element for the .props at the end of the project file (.csproj) which is incorrect. Now .props files are added to the project file as the first child element inside the Project's root element.
Diffstat (limited to 'main')
-rw-r--r--main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakeDotNetProject.cs4
-rw-r--r--main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakeNuGetPackageNewImportsHandler.cs48
-rw-r--r--main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/ImportAndCondition.cs69
-rw-r--r--main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableMonoDevelopProjectSystem.cs7
-rw-r--r--main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj1
-rw-r--r--main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/MonoDevelopProjectSystemTests.cs53
-rw-r--r--main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj2
-rw-r--r--main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/INuGetPackageNewImportsHandler.cs37
-rw-r--r--main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopProjectSystem.cs11
-rw-r--r--main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/NuGetPackageNewImportsHandler.cs65
-rw-r--r--main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementMSBuildExtension.cs6
11 files changed, 257 insertions, 46 deletions
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakeDotNetProject.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakeDotNetProject.cs
index 745d8b8e7f..ed4ccd480d 100644
--- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakeDotNetProject.cs
+++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakeDotNetProject.cs
@@ -105,11 +105,9 @@ namespace MonoDevelop.PackageManagement.Tests.Helpers
return buildAction;
}
- public List<ImportAndCondition> ImportsAdded = new List<ImportAndCondition> ();
-
public void AddImportIfMissing (string name, string condition)
{
- ImportsAdded.Add (new ImportAndCondition (name, condition));
+ throw new ApplicationException ("Obsolete should not be called.");
}
public List<string> ImportsRemoved = new List <string> ();
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakeNuGetPackageNewImportsHandler.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakeNuGetPackageNewImportsHandler.cs
new file mode 100644
index 0000000000..ac2a71ea6a
--- /dev/null
+++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakeNuGetPackageNewImportsHandler.cs
@@ -0,0 +1,48 @@
+//
+// FakeNuGetPackageNewImportsHandler.cs
+//
+// Author:
+// Matt Ward <matt.ward@xamarin.com>
+//
+// Copyright (c) 2016 Xamarin Inc. (http://xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System.Collections.Generic;
+using NuGet;
+
+namespace MonoDevelop.PackageManagement.Tests.Helpers
+{
+ public class FakeNuGetPackageNewImportsHandler : INuGetPackageNewImportsHandler
+ {
+ public bool IsDisposed;
+ public List<ImportAndCondition> ImportsAdded = new List<ImportAndCondition> ();
+
+ public void AddImportIfMissing (string name, string condition, ProjectImportLocation location)
+ {
+ ImportsAdded.Add (new ImportAndCondition (name, condition, location));
+ }
+
+ public void Dispose ()
+ {
+ IsDisposed = true;
+ }
+ }
+}
+
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/ImportAndCondition.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/ImportAndCondition.cs
index 33b99da2fb..c073ef5e2e 100644
--- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/ImportAndCondition.cs
+++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/ImportAndCondition.cs
@@ -1,43 +1,50 @@
-//
-// ImportAndCondition.cs
-//
-// Author:
-// Matt Ward <matt.ward@xamarin.com>
-//
-// Copyright (c) 2014 Xamarin Inc. (http://xamarin.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-using System;
+//
+// ImportAndCondition.cs
+//
+// Author:
+// Matt Ward <matt.ward@xamarin.com>
+//
+// Copyright (c) 2014 Xamarin Inc. (http://xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using NuGet;
+
namespace MonoDevelop.PackageManagement.Tests.Helpers
{
public class ImportAndCondition
- {
- public ImportAndCondition (string name, string condition)
+ {
+ public ImportAndCondition (string name, string condition)
+ : this (name, condition, ProjectImportLocation.Bottom)
+ {
+ }
+
+ public ImportAndCondition (string name, string condition, ProjectImportLocation location)
{
Name = name;
- Condition = condition;
+ Condition = condition;
+ Location = location;
}
public string Name { get; set; }
- public string Condition { get; set; }
+ public string Condition { get; set; }
+ public ProjectImportLocation Location { get; set; }
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableMonoDevelopProjectSystem.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableMonoDevelopProjectSystem.cs
index 8b24a7ed53..150df57537 100644
--- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableMonoDevelopProjectSystem.cs
+++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableMonoDevelopProjectSystem.cs
@@ -47,6 +47,7 @@ namespace MonoDevelop.PackageManagement.Tests.Helpers
public ReferenceAndProjectName ReferenceAndProjectNamePassedToLogAddedReferenceToProject;
public ReferenceAndProjectName ReferenceAndProjectNamePassedToLogRemovedReferenceFromProject;
public FileNameAndProjectName FileNameAndProjectNamePassedToLogAddedFileToProject;
+ public FakeNuGetPackageNewImportsHandler NewImportsHandler;
public static Action<Action> GuiSyncDispatcher = handler => handler.Invoke ();
public static Func<Func<Task>,Task> GuiSyncDispatcherFunc = handler => handler.Invoke();
@@ -119,6 +120,12 @@ namespace MonoDevelop.PackageManagement.Tests.Helpers
FileNameAndProjectNamePassedToLogAddedFileToProject =
new FileNameAndProjectName (fileName, projectName);
}
+
+ protected override INuGetPackageNewImportsHandler CreateNewImportsHandler ()
+ {
+ NewImportsHandler = new FakeNuGetPackageNewImportsHandler ();
+ return NewImportsHandler;
+ }
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj
index eaa9bb43b6..ac04c8f64c 100644
--- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj
+++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj
@@ -213,6 +213,7 @@
<Compile Include="MonoDevelop.PackageManagement.Tests.Helpers\TestableCheckForUpdatesTaskRunner.cs" />
<Compile Include="MonoDevelop.PackageManagement.Tests\MinClientVersionTests.cs" />
<Compile Include="MonoDevelop.PackageManagement.Tests.Helpers\FakeLicenseAcceptanceService.cs" />
+ <Compile Include="MonoDevelop.PackageManagement.Tests.Helpers\FakeNuGetPackageNewImportsHandler.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\core\MonoDevelop.Core\MonoDevelop.Core.csproj">
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/MonoDevelopProjectSystemTests.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/MonoDevelopProjectSystemTests.cs
index 0c43cba071..0fa66464e2 100644
--- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/MonoDevelopProjectSystemTests.cs
+++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/MonoDevelopProjectSystemTests.cs
@@ -87,26 +87,38 @@ namespace MonoDevelop.PackageManagement.Tests
void AssertLastMSBuildChildElementHasProjectAttributeValue (string expectedImport)
{
- ImportAndCondition import = project.ImportsAdded.Last ();
+ ImportAndCondition import = projectSystem.NewImportsHandler.ImportsAdded.Last ();
Assert.AreEqual (expectedImport, import.Name);
}
void AssertLastImportHasCondition (string expectedCondition)
{
- ImportAndCondition import = project.ImportsAdded.Last ();
+ ImportAndCondition import = projectSystem.NewImportsHandler.ImportsAdded.Last ();
Assert.AreEqual (expectedCondition, import.Condition);
}
+ void AssertLastImportHasImportLocation (ProjectImportLocation expectedLocation)
+ {
+ ImportAndCondition import = projectSystem.NewImportsHandler.ImportsAdded.Last ();
+ Assert.AreEqual (expectedLocation, import.Location);
+ }
+
void AssertFirstMSBuildChildElementHasProjectAttributeValue (string expectedImport)
{
- ImportAndCondition import = project.ImportsAdded.First ();
+ ImportAndCondition import = projectSystem.NewImportsHandler.ImportsAdded.First ();
Assert.AreEqual (expectedImport, import.Name);
}
void AssertFirstImportHasCondition (string expectedCondition)
{
- ImportAndCondition import = project.ImportsAdded.First ();
+ ImportAndCondition import = projectSystem.NewImportsHandler.ImportsAdded.First ();
Assert.AreEqual (expectedCondition, import.Condition);
+ }
+
+ void AssertFirstImportHasImportLocation (ProjectImportLocation expectedLocation)
+ {
+ ImportAndCondition import = projectSystem.NewImportsHandler.ImportsAdded.First ();
+ Assert.AreEqual (expectedLocation, import.Location);
}
void AssertImportRemoved (string expectedImportRemoved)
@@ -899,6 +911,7 @@ namespace MonoDevelop.PackageManagement.Tests
projectSystem.AddImport (targetPath, ProjectImportLocation.Bottom);
AssertLastMSBuildChildElementHasProjectAttributeValue (@"..\packages\Foo.0.1\build\Foo.targets");
+ AssertLastImportHasImportLocation (ProjectImportLocation.Bottom);
}
[Test]
@@ -911,6 +924,7 @@ namespace MonoDevelop.PackageManagement.Tests
projectSystem.AddImport (targetPath, ProjectImportLocation.Bottom);
AssertLastMSBuildChildElementHasProjectAttributeValue (@"packages\Foo.0.1\build\Foo.targets");
+ AssertLastImportHasImportLocation (ProjectImportLocation.Bottom);
}
[Test]
@@ -923,6 +937,7 @@ namespace MonoDevelop.PackageManagement.Tests
projectSystem.AddImport (targetPath, ProjectImportLocation.Bottom);
AssertLastImportHasCondition ("Exists('..\\packages\\Foo.0.1\\build\\Foo.targets')");
+ AssertLastImportHasImportLocation (ProjectImportLocation.Bottom);
}
[Test]
@@ -931,11 +946,12 @@ namespace MonoDevelop.PackageManagement.Tests
CreateTestProject (@"d:\projects\MyProject\MyProject\MyProject.csproj");
CreateProjectSystem (project);
string targetPath = @"d:\projects\MyProject\packages\Foo.0.1\build\Foo.targets".ToNativePath ();
- projectSystem.AddImport (targetPath, ProjectImportLocation.Bottom);
projectSystem.AddImport (targetPath, ProjectImportLocation.Bottom);
+ Assert.AreEqual (1, projectSystem.NewImportsHandler.ImportsAdded.Count);
- Assert.AreEqual (2, project.ImportsAdded.Count);
+ projectSystem.AddImport (targetPath, ProjectImportLocation.Bottom);
+ Assert.AreEqual (1, projectSystem.NewImportsHandler.ImportsAdded.Count);
}
[Test]
@@ -945,11 +961,12 @@ namespace MonoDevelop.PackageManagement.Tests
CreateProjectSystem (project);
string targetPath1 = @"d:\projects\MyProject\packages\Foo.0.1\build\Foo.targets".ToNativePath ();
string targetPath2 = @"d:\projects\MyProject\packages\Foo.0.1\BUILD\FOO.TARGETS".ToNativePath ();
+
projectSystem.AddImport (targetPath1, ProjectImportLocation.Bottom);
+ Assert.AreEqual (1, projectSystem.NewImportsHandler.ImportsAdded.Count);
projectSystem.AddImport (targetPath2, ProjectImportLocation.Bottom);
-
- Assert.AreEqual (2, project.ImportsAdded.Count);
+ Assert.AreEqual (1, projectSystem.NewImportsHandler.ImportsAdded.Count);
}
[Test]
@@ -988,7 +1005,7 @@ namespace MonoDevelop.PackageManagement.Tests
projectSystem.RemoveImport (targetPath2);
- Assert.AreEqual (1, project.ImportsAdded.Count);
+ Assert.AreEqual (1, projectSystem.NewImportsHandler.ImportsAdded.Count);
Assert.AreEqual (2, project.ImportsRemoved.Count);
}
@@ -1013,6 +1030,7 @@ namespace MonoDevelop.PackageManagement.Tests
projectSystem.AddImport (targetPath, ProjectImportLocation.Top);
AssertFirstMSBuildChildElementHasProjectAttributeValue (@"..\packages\Foo.0.1\build\Foo.targets");
+ AssertFirstImportHasImportLocation (ProjectImportLocation.Top);
}
[Test]
@@ -1025,6 +1043,7 @@ namespace MonoDevelop.PackageManagement.Tests
projectSystem.AddImport (targetPath, ProjectImportLocation.Top);
AssertFirstImportHasCondition ("Exists('..\\packages\\Foo.0.1\\build\\Foo.targets')");
+ AssertFirstImportHasImportLocation (ProjectImportLocation.Top);
}
[Test]
@@ -1033,11 +1052,13 @@ namespace MonoDevelop.PackageManagement.Tests
CreateTestProject (@"d:\projects\MyProject\MyProject\MyProject.csproj");
CreateProjectSystem (project);
string targetPath = @"d:\projects\MyProject\packages\Foo.0.1\build\Foo.targets".ToNativePath ();
+
projectSystem.AddImport (targetPath, ProjectImportLocation.Top);
+ Assert.AreEqual (1, projectSystem.NewImportsHandler.ImportsAdded.Count);
projectSystem.AddImport (targetPath, ProjectImportLocation.Top);
- Assert.AreEqual (2, project.ImportsAdded.Count);
+ Assert.AreEqual (1, projectSystem.NewImportsHandler.ImportsAdded.Count);
}
[Test]
@@ -1217,6 +1238,18 @@ namespace MonoDevelop.PackageManagement.Tests
Assert.AreEqual (fileName, referenceBeingRemoved.HintPath.ToString ());
Assert.IsFalse (projectIsSaved);
+ }
+
+ [Test]
+ public void AddImport_FullImportFilePathAndBottomOfProject_ImportHandlerIsDisposed ()
+ {
+ CreateTestProject (@"d:\projects\MyProject\MyProject\MyProject.csproj");
+ CreateProjectSystem (project);
+ string targetPath = @"d:\projects\MyProject\packages\Foo.0.1\build\Foo.targets".ToNativePath ();
+
+ projectSystem.AddImport (targetPath, ProjectImportLocation.Bottom);
+
+ Assert.IsTrue (projectSystem.NewImportsHandler.IsDisposed);
}
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj
index e5c459e8b8..f874ec3852 100644
--- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj
+++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj
@@ -377,6 +377,8 @@
<Compile Include="MonoDevelop.PackageManagement\MonoDevelopProjectSystemFactory.cs" />
<Compile Include="MonoDevelop.PackageManagement\PackageManagementBackgroundDispatcher.cs" />
<Compile Include="MonoDevelop.PackageManagement\PackageManagementSolutionProjectService.cs" />
+ <Compile Include="MonoDevelop.PackageManagement\NuGetPackageNewImportsHandler.cs" />
+ <Compile Include="MonoDevelop.PackageManagement\INuGetPackageNewImportsHandler.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="MonoDevelop.PackageManagement.addin.xml" />
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/INuGetPackageNewImportsHandler.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/INuGetPackageNewImportsHandler.cs
new file mode 100644
index 0000000000..64b1899efa
--- /dev/null
+++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/INuGetPackageNewImportsHandler.cs
@@ -0,0 +1,37 @@
+//
+// INuGetPackageNewImportsHandler.cs
+//
+// Author:
+// Matt Ward <matt.ward@xamarin.com>
+//
+// Copyright (c) 2016 Xamarin Inc. (http://xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using NuGet;
+
+namespace MonoDevelop.PackageManagement
+{
+ public interface INuGetPackageNewImportsHandler : IDisposable
+ {
+ void AddImportIfMissing (string name, string condition, ProjectImportLocation location);
+ }
+}
+
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopProjectSystem.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopProjectSystem.cs
index 4ed9da4aa6..fb99bf7a38 100644
--- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopProjectSystem.cs
+++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopProjectSystem.cs
@@ -407,11 +407,18 @@ namespace MonoDevelop.PackageManagement
GuiSyncDispatch (async () => {
string relativeTargetPath = GetRelativePath (targetPath);
string condition = GetCondition (relativeTargetPath);
- project.AddImportIfMissing (relativeTargetPath, condition);
- await project.SaveAsync ();
+ using (var handler = CreateNewImportsHandler ()) {
+ handler.AddImportIfMissing (relativeTargetPath, condition, location);
+ await project.SaveAsync ();
+ }
});
}
+ protected virtual INuGetPackageNewImportsHandler CreateNewImportsHandler ()
+ {
+ return new NuGetPackageNewImportsHandler ();
+ }
+
static string GetCondition (string targetPath)
{
return String.Format ("Exists('{0}')", targetPath);
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/NuGetPackageNewImportsHandler.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/NuGetPackageNewImportsHandler.cs
new file mode 100644
index 0000000000..e1bd33c1cf
--- /dev/null
+++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/NuGetPackageNewImportsHandler.cs
@@ -0,0 +1,65 @@
+//
+// NuGetPackageNewImportsHandler.cs
+//
+// Author:
+// Matt Ward <matt.ward@xamarin.com>
+//
+// Copyright (c) 2016 Xamarin Inc. (http://xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using MonoDevelop.Projects.MSBuild;
+using NuGet;
+
+namespace MonoDevelop.PackageManagement
+{
+ public class NuGetPackageNewImportsHandler : INuGetPackageNewImportsHandler
+ {
+ string name;
+ string condition;
+ ProjectImportLocation location;
+
+ public NuGetPackageNewImportsHandler ()
+ {
+ PackageManagementMSBuildExtension.NewImportsHandler = this;
+ }
+
+ public void Dispose ()
+ {
+ PackageManagementMSBuildExtension.NewImportsHandler = null;
+ }
+
+ public void AddImportIfMissing (string name, string condition, ProjectImportLocation location)
+ {
+ this.name = name;
+ this.condition = condition;
+ this.location = location;
+ }
+
+ public void UpdateProject (MSBuildProject project)
+ {
+ if (String.IsNullOrEmpty (name))
+ return;
+
+ project.AddImportIfMissing (name, location, condition);
+ }
+ }
+}
+
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementMSBuildExtension.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementMSBuildExtension.cs
index 4e6a65ae4f..d8138d8d8f 100644
--- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementMSBuildExtension.cs
+++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementMSBuildExtension.cs
@@ -34,6 +34,7 @@ namespace MonoDevelop.PackageManagement
public class PackageManagementMSBuildExtension : ProjectExtension
{
public static EnsureNuGetPackageBuildImportsTargetUpdater Updater;
+ public static NuGetPackageNewImportsHandler NewImportsHandler;
protected override void OnWriteProject (ProgressMonitor monitor, MSBuildProject msproject)
{
@@ -47,6 +48,11 @@ namespace MonoDevelop.PackageManagement
if (currentUpdater != null) {
currentUpdater.UpdateProject (msproject);
}
+
+ NuGetPackageNewImportsHandler importsHandler = NewImportsHandler;
+ if (importsHandler != null) {
+ importsHandler.UpdateProject (msproject);
+ }
}
}
}