diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Commands/PublishToFolderBaseCommandHandler.cs b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Commands/PublishToFolderBaseCommandHandler.cs index 11d3350f8fb..2c6f8242127 100644 --- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Commands/PublishToFolderBaseCommandHandler.cs +++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Commands/PublishToFolderBaseCommandHandler.cs @@ -1,5 +1,5 @@ using System; -using System.Linq; +using System.Threading; using System.Threading.Tasks; using System.IO; using MonoDevelop.Components.Commands; @@ -12,7 +12,6 @@ using MonoDevelop.DotNetCore; using MonoDevelop.Core.ProgressMonitoring; using Xwt; -using MonoDevelop.Core.Instrumentation; namespace MonoDevelop.AspNetCore.Commands { @@ -85,23 +84,20 @@ public async Task Publish (PublishCommandItem item) counterMetadata.SetFailure (); return; } - var dotnetPath = DotNetCoreRuntime.FileName; + progressMonitor.BeginTask ("dotnet publish", 1); - var process = Runtime.ProcessService.StartConsoleProcess ( - dotnetPath, + + int publishExitCode = await RunPublishCommand ( BuildArgs (item), item.Project.BaseDirectory, - consoleMonitor.Console); - - using (progressMonitor.CancellationToken.Register (process.Cancel)) { - await process.Task; - } + consoleMonitor.Console, + progressMonitor.CancellationToken); if (!progressMonitor.CancellationToken.IsCancellationRequested) { - if (process.ExitCode != 0) { + if (publishExitCode != 0) { counterMetadata.SetFailure (); - progressMonitor.ReportError (GettextCatalog.GetString ("dotnet publish returned: {0}", process.ExitCode)); - LoggingService.LogError ($"Unknown exit code returned from 'dotnet publish --output {item.Profile.PublishUrl}': {process.ExitCode}"); + progressMonitor.ReportError (GettextCatalog.GetString ("dotnet publish returned: {0}", publishExitCode)); + LoggingService.LogError ($"Unknown exit code returned from 'dotnet publish --output {item.Profile.PublishUrl}': {publishExitCode}"); } else { counterMetadata.SetSuccess (); OpenFolder (item.Profile.PublishUrl); @@ -125,6 +121,17 @@ public async Task Publish (PublishCommandItem item) } } + internal async Task RunPublishCommand (string args, string wokingDirectory, OperationConsole console, CancellationToken сancellationToken) + { + var process = Runtime.ProcessService.StartConsoleProcess (DotNetCoreRuntime.FileName, args, wokingDirectory, console); + + using (сancellationToken.Register (process.Cancel)) { + await process.Task; + } + + return process.ExitCode; + } + void OpenFolder (string path) { if (!Uri.TryCreate (path, UriKind.Absolute, out var pathUri)) { diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests.csproj b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests.csproj index 9cc8f99e812..0bec0dec1ad 100644 --- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests.csproj +++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests.csproj @@ -27,6 +27,7 @@ + diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishToFolderTests.cs b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishToFolderTests.cs new file mode 100644 index 00000000000..17d81e548f9 --- /dev/null +++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishToFolderTests.cs @@ -0,0 +1,94 @@ +// +// PublishToFolderTests.cs +// +// Author: +// Oleksii Sachek +// +// Copyright (c) 2020 +// +// 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; +using System.Threading.Tasks; +using IdeUnitTests; +using NUnit.Framework; +using UnitTests; +using MonoDevelop.AspNetCore.Commands; +using MonoDevelop.Projects; + +namespace MonoDevelop.AspNetCore.Tests +{ + [TestFixture] + public class PublishToFolderTests : TestBase + { + PublishToFolderCommandHandler publishToFolderCommandHandler; + + [SetUp] + public async Task SetUp () + { + publishToFolderCommandHandler = new PublishToFolderCommandHandler (); + } + + [Test] + // .NET Core 2.2, regular + [TestCase ("aspnetcore-empty-22", "publish --output bin/Release/netcoreapp/publish")] + [TestCase ("aspnetcore-empty-22", "publish --configuration Debug --output bin/debug-22")] + [TestCase ("aspnetcore-empty-22", "publish --configuration Release --output bin/release-22")] + // .NET Core 2.2, self-contained + // OSX + [TestCase ("aspnetcore-empty-22", "publish --configuration Release --self-contained --runtime osx-x64 --output bin/release-22-self-contained-osx")] + // Windows + [TestCase ("aspnetcore-empty-22", "publish --configuration Release --self-contained --runtime win-x64 --output bin/release-22-self-contained-win-x64")] + [TestCase ("aspnetcore-empty-22", "publish --configuration Release --self-contained --runtime win-x86 --output bin/release-22-self-contained-win-x86")] + [TestCase ("aspnetcore-empty-22", "publish --configuration Release --self-contained --runtime win-arm --output bin/release-22-self-contained-win-arm")] + [TestCase ("aspnetcore-empty-22", "publish --configuration Release --self-contained --runtime win-arm64 --output bin/release-22self-contained-win-arm64")] + // Linux + [TestCase ("aspnetcore-empty-22", "publish --configuration Release --self-contained --runtime linux-x64 --output bin/release-22-self-contained-linux-x64")] + [TestCase ("aspnetcore-empty-22", "publish --configuration Release --self-contained --runtime linux-musl-x64 --output bin/release-22-self-contained-linux-musl-x64")] + [TestCase ("aspnetcore-empty-22", "publish --configuration Release --self-contained --runtime linux-arm --output bin/release-22-self-contained-linux-arm")] + // .NET Core 3.0, regular + [TestCase ("aspnetcore-empty-30", "publish --output bin/Release/netcoreapp/publish")] + [TestCase ("aspnetcore-empty-30", "publish --configuration Debug --output bin/debug-22")] + [TestCase ("aspnetcore-empty-30", "publish --configuration Release --output bin/release-22")] + // .NET Core 3.0, self-contained + // OSX + [TestCase ("aspnetcore-empty-30", "publish --configuration Release --self-contained --runtime osx-x64 --output bin/release-22-self-contained-osx")] + // Windows + [TestCase ("aspnetcore-empty-30", "publish --configuration Release --self-contained --runtime win-x64 --output bin/release-22-self-contained-win-x64")] + [TestCase ("aspnetcore-empty-30", "publish --configuration Release --self-contained --runtime win-x86 --output bin/release-22-self-contained-win-x86")] + [TestCase ("aspnetcore-empty-30", "publish --configuration Release --self-contained --runtime win-arm --output bin/release-22-self-contained-win-arm")] + [TestCase ("aspnetcore-empty-30", "publish --configuration Release --self-contained --runtime win-arm64 --output bin/release-22self-contained-win-arm64")] + // Linux + [TestCase ("aspnetcore-empty-30", "publish --configuration Release --self-contained --runtime linux-x64 --output bin/release-22-self-contained-linux-x64")] + [TestCase ("aspnetcore-empty-30", "publish --configuration Release --self-contained --runtime linux-musl-x64 --output bin/release-22-self-contained-linux-musl-x64")] + [TestCase ("aspnetcore-empty-30", "publish --configuration Release --self-contained --runtime linux-arm --output bin/release-22-self-contained-linux-arm")] + public async Task PublishToFolder (string solutionName, string publishArgs) + { + var solutionFileName = Util.GetSampleProject (solutionName, $"{solutionName}.sln"); + var solution = (Solution)await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solutionFileName); + var project = (DotNetProject)solution.GetAllProjects ().Single (); + var operationConsole = new MockOperationConsole (); + + int exitCode = await publishToFolderCommandHandler.RunPublishCommand (publishArgs, project.BaseDirectory, operationConsole, CancellationToken.None); + + Assert.AreEqual (0, exitCode, "Publish to Folder command exit code must be 0"); + } + } +} diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.csproj b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.csproj index eca7d6cbc08..dc94f9741bc 100644 --- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.csproj +++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.csproj @@ -218,5 +218,8 @@ + + +