Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit 6a96c48

Browse files
author
Rodrigo Moya
authored
Merge pull request #8869 from mono/fix-950073
Add support to Pack .net std lib projects
2 parents 69472ac + 918350e commit 6a96c48

File tree

8 files changed

+176
-3
lines changed

8 files changed

+176
-3
lines changed

main/src/addins/MonoDevelop.AspNetCore/Properties/MonoDevelop.AspNetCore.addin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@
884884
</Extension>
885885

886886
<Extension path = "/MonoDevelop/Ide/MainMenu/Build">
887-
<CommandItem id = "MonoDevelop.AspNetCore.Commands.PublishToFolder" />
887+
<CommandItem id = "MonoDevelop.AspNetCore.Commands.PublishToFolder" insertbefore="MonoDevelop.DotNetCore.Commands.PackSeparator" />
888888
<SeparatorItem id = "ProfilesSeparator" />
889889
<CommandItem id = "MonoDevelop.AspNetCore.Commands.PublishToFolderProfiles" />
890890
</Extension>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using MonoDevelop.Components.Commands;
6+
using MonoDevelop.Core;
7+
using MonoDevelop.Ide;
8+
using MonoDevelop.Projects;
9+
10+
namespace MonoDevelop.DotNetCore.Commands
11+
{
12+
class PackCommandHandler : CommandHandler
13+
{
14+
protected override void Run (object dataItem)
15+
{
16+
var project = IdeApp.ProjectOperations.CurrentSelectedProject as DotNetProject;
17+
if (project == null)
18+
return;
19+
20+
var buildTarget = new PackProjectBuildTarget (project);
21+
IdeApp.ProjectOperations.Build (buildTarget);
22+
}
23+
24+
protected override void Update (CommandInfo info)
25+
{
26+
var project = IdeApp.ProjectOperations.CurrentSelectedProject as DotNetProject;
27+
info.Enabled = info.Visible = project != null && IsDotNetCoreProject (project);
28+
}
29+
30+
bool IsDotNetCoreProject (Project project)
31+
{
32+
return project.MSBuildProject.GetReferencedSDKs ().Any ();
33+
}
34+
}
35+
36+
class PackProjectBuildTarget : IBuildTarget
37+
{
38+
DotNetProject project;
39+
40+
public PackProjectBuildTarget (DotNetProject project)
41+
{
42+
this.project = project;
43+
}
44+
45+
public string Name {
46+
get { return project.Name; }
47+
}
48+
49+
public async Task<BuildResult> Build (ProgressMonitor monitor, ConfigurationSelector configuration, bool buildReferencedTargets = false, OperationContext operationContext = null)
50+
{
51+
var result = await project.Build (monitor, configuration, buildReferencedTargets, operationContext);
52+
if (result.Failed)
53+
return result;
54+
55+
// Run the "Pack" target on the project
56+
var packResult = (await project.RunTarget (monitor, "Pack", configuration, new TargetEvaluationContext (operationContext))).BuildResult;
57+
return result.Append (packResult);
58+
}
59+
60+
public bool CanBuild (ConfigurationSelector configuration)
61+
{
62+
throw new NotImplementedException ();
63+
}
64+
65+
public bool CanExecute (ExecutionContext context, ConfigurationSelector configuration)
66+
{
67+
throw new NotImplementedException ();
68+
}
69+
70+
public Task<BuildResult> Clean (ProgressMonitor monitor, ConfigurationSelector configuration, OperationContext operationContext = null)
71+
{
72+
throw new NotImplementedException ();
73+
}
74+
75+
public Task Execute (ProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configuration)
76+
{
77+
throw new NotImplementedException ();
78+
}
79+
80+
public IEnumerable<IBuildTarget> GetExecutionDependencies ()
81+
{
82+
throw new NotImplementedException ();
83+
}
84+
85+
public bool NeedsBuilding (ConfigurationSelector configuration)
86+
{
87+
throw new NotImplementedException ();
88+
}
89+
90+
public Task PrepareExecution (ProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configuration)
91+
{
92+
throw new NotImplementedException ();
93+
}
94+
}
95+
96+
}

main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<Compile Include="MonoDevelop.DotNetCore.Tests\TestableTargetFrameworkNodeBuilder.cs" />
4141
<Compile Include="MonoDevelop.DotNetCore.Tests\TestableFrameworkReferencesNodeBuilder.cs" />
4242
<Compile Include="MonoDevelop.DotNetCore.Tests\FakeUpdatedPackagesInWorkspace.cs" />
43+
<Compile Include="MonoDevelop.DotNetCore.Tests\PackProjectTests.cs" />
4344
</ItemGroup>
4445
<ItemGroup>
4546
<ProjectReference Include="..\..\..\..\external\guiunit\src\framework\GuiUnit_NET_4_5.csproj">
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// PackProjectTests.cs
3+
//
4+
// Author:
5+
// Jason Imison <[email protected]>
6+
//
7+
// Copyright (c) 2019 Microsoft
8+
//
9+
// Permission is hereby granted, free of charge, to any person obtaining a copy
10+
// of this software and associated documentation files (the "Software"), to deal
11+
// in the Software without restriction, including without limitation the rights
12+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
// copies of the Software, and to permit persons to whom the Software is
14+
// furnished to do so, subject to the following conditions:
15+
//
16+
// The above copyright notice and this permission notice shall be included in
17+
// all copies or substantial portions of the Software.
18+
//
19+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
// THE SOFTWARE.
26+
using System;
27+
using System.IO;
28+
using System.Threading.Tasks;
29+
using MonoDevelop.Core;
30+
using MonoDevelop.DotNetCore.Commands;
31+
using MonoDevelop.Projects;
32+
using NUnit.Framework;
33+
using UnitTests;
34+
35+
namespace MonoDevelop.DotNetCore.Tests
36+
{
37+
[TestFixture]
38+
public class PackProjectTests
39+
{
40+
[Test]
41+
public async Task Should_pack_multi_target_project ()
42+
{
43+
FilePath solFile = Util.GetSampleProject ("DotNetCoreMultiTargetFrameworkProperty", "DotNetCoreMultiTargetFrameworkProperty.sln");
44+
45+
var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile);
46+
var p = (DotNetProject)sol.Items [0];
47+
48+
var packTarget = new PackProjectBuildTarget (p);
49+
var monitor = Util.GetMonitor ();
50+
var res = await p.RunTarget (monitor, "Restore", ConfigurationSelector.Default);
51+
var result = await packTarget.Build (monitor, ConfigurationSelector.Default);
52+
Assert.AreEqual (0, result.ErrorCount);
53+
var nupkg = sol.FileName.ParentDirectory.Combine ("bin", "Debug", "DotNetCoreMultiTargetFrameworkProperty.1.0.0.nupkg");
54+
Assert.IsTrue (File.Exists (nupkg));
55+
}
56+
}
57+
}
58+

main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
<Compile Include="MonoDevelop.DotNetCore.NodeBuilders\FrameworkReferencesNode.cs" />
9797
<Compile Include="MonoDevelop.DotNetCore.NodeBuilders\FrameworkReferencesNodeBuilder.cs" />
9898
<Compile Include="MonoDevelop.DotNetCore\DotNetCoreRuntimeSystemInformation.cs" />
99+
<Compile Include="MonoDevelop.DotNetCore.Commands\PackCommandHandler.cs" />
99100
</ItemGroup>
100101
<ItemGroup>
101102
<ProjectReference Include="..\..\..\external\mono-addins\Mono.Addins\Mono.Addins.csproj">

main/src/addins/MonoDevelop.DotNetCore/Properties/MonoDevelop.DotNetCore.addin.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,4 +1599,20 @@
15991599
<Extension path="/MonoDevelop/DesignerSupport/PropertyProviders">
16001600
<Class class="MonoDevelop.DotNetCore.NodeBuilders.PackageDependencyNodePropertyProvider" />
16011601
</Extension>
1602+
1603+
<!-- Pack command -->
1604+
<Extension path = "/MonoDevelop/Ide/Commands/Project">
1605+
<Command id = "MonoDevelop.DotNetCore.Commands.Pack"
1606+
defaultHandler = "MonoDevelop.DotNetCore.Commands.PackCommandHandler"
1607+
_label = "Pack" />
1608+
</Extension>
1609+
1610+
<Extension path = "/MonoDevelop/Ide/MainMenu/Build">
1611+
<SeparatorItem id="MonoDevelop.DotNetCore.Commands.PackSeparator" />
1612+
<CommandItem id="MonoDevelop.DotNetCore.Commands.Pack" />
1613+
</Extension>
1614+
1615+
<Extension path="/MonoDevelop/Ide/ContextMenu/ProjectPad">
1616+
<CommandItem id="MonoDevelop.DotNetCore.Commands.Pack" insertbefore="Publish" />
1617+
</Extension>
16021618
</ExtensionModel>

main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ internal protected virtual Dictionary<string, string> CreateGlobalProperties (Co
15921592
{
15931593
var properties = new Dictionary<string, string> ();
15941594
string framework = activeTargetFramework;
1595-
if (framework != null && target != ProjectService.BuildTarget && target != ProjectService.CleanTarget)
1595+
if (framework != null && target != ProjectService.BuildTarget && target != ProjectService.CleanTarget && target != ProjectService.PackTarget)
15961596
properties ["TargetFramework"] = framework;
15971597

15981598
return properties;

main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public class ProjectService
5858

5959
public const string BuildTarget = "Build";
6060
public const string CleanTarget = "Clean";
61-
61+
public const string PackTarget = "Pack";
62+
6263
const string SerializableClassesExtensionPath = "/MonoDevelop/ProjectModel/SerializableClasses";
6364
const string ProjectBindingsExtensionPath = "/MonoDevelop/ProjectModel/ProjectBindings";
6465
const string WorkspaceObjectReadersPath = "/MonoDevelop/ProjectModel/WorkspaceObjectReaders";

0 commit comments

Comments
 (0)