diff options
author | Lluis Sanchez <llsan@microsoft.com> | 2019-03-06 16:21:55 +0300 |
---|---|---|
committer | Lluis Sanchez <llsan@microsoft.com> | 2019-03-06 16:21:55 +0300 |
commit | 7b364e60efda7b3c3b6983e56f0e1e05ece3bd1f (patch) | |
tree | d9068a5fe707d22b829c9f3a2fa9c247133ca1b1 /main | |
parent | eb5022f9d9ee7eeed5f979d2de9b1d033f66068e (diff) | |
parent | 72efd06d586dbe36d20d1b88e53a290bebc5b290 (diff) |
Merge remote-tracking branch 'origin/release-8.0-integration' into release-8.0
Diffstat (limited to 'main')
7 files changed, 151 insertions, 6 deletions
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 d0417914be..2975138b01 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 @@ -148,6 +148,7 @@ <Compile Include="MonoDevelop.PackageManagement.Tests\ProjectReferenceMaintainerTests.cs" /> <Compile Include="MonoDevelop.PackageManagement.Tests\FullyQualifiedReferencePathTests.cs" /> <Compile Include="MonoDevelop.PackageManagement.Tests\MSBuildPackageSpecCreatorTests.cs" /> + <Compile Include="MonoDevelop.PackageManagement.Tests\InstallPackageWithAvailableItemNameTests.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/InstallPackageWithAvailableItemNameTests.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/InstallPackageWithAvailableItemNameTests.cs new file mode 100644 index 0000000000..c32ec699b7 --- /dev/null +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/InstallPackageWithAvailableItemNameTests.cs @@ -0,0 +1,74 @@ +// +// InstallPackageWithAvailableItemNameTests.cs +// +// Author: +// Matt Ward <matt.ward@microsoft.com> +// +// Copyright (c) 2019 Microsoft +// +// 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.Linq; +using System.Threading.Tasks; +using MonoDevelop.PackageManagement.Tests.Helpers; +using MonoDevelop.Projects; +using NuGet.Versioning; +using NUnit.Framework; +using UnitTests; + +namespace MonoDevelop.PackageManagement.Tests +{ + [TestFixture] + public class InstallPackageWithAvailableItemNameTests : RestoreTestBase + { + [Test] + public async Task InstallPackage_PackageDefinesCustomAvailableItemNames_BuildActionsIncludeCustomAvailableItemNames () + { + string solutionFileName = Util.GetSampleProject ("RestoreStylePackageReference", "RestoreStylePackageReference.sln"); + using (solution = (Solution)await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solutionFileName)) { + CreateNuGetConfigFile (solution.BaseDirectory); + var project = (DotNetProject)solution.FindProjectByName ("RestoreStylePackageReference"); + + var originalBuildActions = project.GetBuildActions (); + await InstallNuGetPackage (project, "Test.Xam.AvailableItemName", "0.1.0"); + var updatedBuildActions = project.GetBuildActions (); + + Assert.IsFalse (originalBuildActions.Contains ("TestXamAvailableItem")); + Assert.That (updatedBuildActions, Contains.Item ("TestXamAvailableItem")); + } + } + + Task InstallNuGetPackage (DotNetProject project, string packageId, string packageVersion) + { + var solutionManager = new MonoDevelopSolutionManager (project.ParentSolution); + var context = CreateNuGetProjectContext (solutionManager.Settings); + var sources = solutionManager.CreateSourceRepositoryProvider ().GetRepositories (); + + var action = new InstallNuGetPackageAction (sources, solutionManager, new DotNetProjectProxy (project), context); + action.LicensesMustBeAccepted = false; + action.OpenReadmeFile = false; + action.PackageId = packageId; + action.Version = NuGetVersion.Parse (packageVersion); + + return Task.Run (() => { + action.Execute (); + }); + } + } +} diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageReferenceNuGetProject.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageReferenceNuGetProject.cs index 575200ece5..e755b501bb 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageReferenceNuGetProject.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageReferenceNuGetProject.cs @@ -54,6 +54,7 @@ namespace MonoDevelop.PackageManagement IPackageManagementEvents packageManagementEvents; string msbuildProjectPath; string projectName; + bool reevaluationRequired; public PackageReferenceNuGetProject (DotNetProject project, ConfigurationSelector configuration) : this (project, configuration, PackageManagementServices.PackageManagementEvents) @@ -241,13 +242,16 @@ namespace MonoDevelop.PackageManagement throw new InvalidOperationException (GettextCatalog.GetString ("Unable to create package spec for project. '{0}'", project.FileName)); } - public override Task PostProcessAsync (INuGetProjectContext nuGetProjectContext, CancellationToken token) + public override async Task PostProcessAsync (INuGetProjectContext nuGetProjectContext, CancellationToken token) { - Runtime.RunInMainThread (() => { + await Runtime.RunInMainThread (async () => { + if (reevaluationRequired) { + await DotNetProject.ReevaluateProject (new ProgressMonitor ()); + } DotNetProject.NotifyModified ("References"); }); - return base.PostProcessAsync (nuGetProjectContext, token); + await base.PostProcessAsync (nuGetProjectContext, token); } public void OnBeforeUninstall (IEnumerable<NuGetProjectAction> actions) @@ -256,6 +260,7 @@ namespace MonoDevelop.PackageManagement public void OnAfterExecuteActions (IEnumerable<NuGetProjectAction> actions) { + reevaluationRequired = actions.Any (action => action.NuGetProjectActionType == NuGetProjectActionType.Install); } public void NotifyProjectReferencesChanged (bool includeTransitiveProjectReferences) diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs index 845be48fe0..81221d827b 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs @@ -1345,17 +1345,24 @@ namespace MonoDevelop.Core internal void OnFileCreated (FileEventArgs args) { - FileCreated?.Invoke (this, args); + FileCreated?.Invoke (this, Clone (args)); } internal void OnFileRemoved (FileEventArgs args) { - FileRemoved?.Invoke (this, args); + FileRemoved?.Invoke (this, Clone (args)); } internal void OnFileRenamed (FileCopyEventArgs args) { - FileRenamed?.Invoke (this, args); + FileRenamed?.Invoke (this, Clone (args)); + } + + static T Clone<T> (T args) where T : FileEventArgs, new() + { + var result = new T (); + result.AddRange (args); + return result; } } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs index 2fcd862be2..d5599be9d8 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs @@ -2772,6 +2772,9 @@ namespace MonoDevelop.Projects // Read available item types loadedAvailableItemNames = msproject.EvaluatedItems.Where (i => i.Name == "AvailableItemName").Select (i => i.Include).ToArray (); + + // Ensure buildActions are refreshed if loadedAvailableItemNames have been updated. + buildActions = null; } List<ConfigData> GetConfigData (MSBuildProject msproject, bool includeEvaluated) diff --git a/main/tests/test-projects/RestoreStylePackageReference/RestoreStylePackageReference.csproj b/main/tests/test-projects/RestoreStylePackageReference/RestoreStylePackageReference.csproj new file mode 100644 index 0000000000..6c1cfcf8f3 --- /dev/null +++ b/main/tests/test-projects/RestoreStylePackageReference/RestoreStylePackageReference.csproj @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>10.0.0</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{7F63CBE6-2FE7-47A7-8930-EA078DA05062}</ProjectGuid> + <OutputType>Library</OutputType> + <AssemblyName>RestoreStylePackageReference</AssemblyName> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <RestoreProjectStyle>PackageReference</RestoreProjectStyle> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <Optimize>true</Optimize> + <OutputPath>bin\Debug</OutputPath> + <DefineConstants>DEBUG</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <ConsolePause>false</ConsolePause> + <CheckForOverflowUnderflow>true</CheckForOverflowUnderflow> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <Optimize>true</Optimize> + <OutputPath>bin\Release</OutputPath> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <ConsolePause>false</ConsolePause> + <CheckForOverflowUnderflow>true</CheckForOverflowUnderflow> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + </ItemGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> +</Project>
\ No newline at end of file diff --git a/main/tests/test-projects/RestoreStylePackageReference/RestoreStylePackageReference.sln b/main/tests/test-projects/RestoreStylePackageReference/RestoreStylePackageReference.sln new file mode 100644 index 0000000000..473e43ef36 --- /dev/null +++ b/main/tests/test-projects/RestoreStylePackageReference/RestoreStylePackageReference.sln @@ -0,0 +1,19 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RestoreStylePackageReference", "RestoreStylePackageReference.csproj", "{7F63CBE6-2FE7-47A7-8930-EA078DA05062}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7F63CBE6-2FE7-47A7-8930-EA078DA05062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7F63CBE6-2FE7-47A7-8930-EA078DA05062}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7F63CBE6-2FE7-47A7-8930-EA078DA05062}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7F63CBE6-2FE7-47A7-8930-EA078DA05062}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + EndGlobalSection +EndGlobal |