Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Fixed relative path handling for pack and publish command #7166

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/dotnet/commands/dotnet-pack/PackCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Tools;
Expand All @@ -22,7 +23,7 @@ public static Command Pack() =>
LocalizableStrings.CmdOutputDirDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdOutputDir)
.ForwardAsSingle(o => $"/p:PackageOutputPath={o.Arguments.Single()}")),
.ForwardAsSingle(o => $"/p:PackageOutputPath={Path.GetFullPath(o.Arguments.Single())}")),
Create.Option(
"--no-build",
LocalizableStrings.CmdNoBuildOptionDescription,
Expand Down
3 changes: 2 additions & 1 deletion src/dotnet/commands/dotnet-publish/PublishCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Tools;
Expand All @@ -22,7 +23,7 @@ public static Command Publish() =>
LocalizableStrings.OutputOptionDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.OutputOption)
.ForwardAsSingle(o => $"/p:PublishDir={o.Arguments.Single()}")),
.ForwardAsSingle(o => $"/p:PublishDir={Path.GetFullPath(o.Arguments.Single())}")),
CommonOptions.FrameworkOption(),
CommonOptions.RuntimeOption(),
CommonOptions.ConfigurationOption(),
Expand Down
6 changes: 4 additions & 2 deletions test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using FluentAssertions;
using Xunit;
using System;
using System.IO;
using System.Linq;

namespace Microsoft.DotNet.Cli.MSBuild.Tests
Expand All @@ -15,8 +16,8 @@ public class GivenDotnetPackInvocation

[Theory]
[InlineData(new string[] { }, "")]
[InlineData(new string[] { "-o", "<packageoutputpath>" }, "/p:PackageOutputPath=<packageoutputpath>")]
[InlineData(new string[] { "--output", "<packageoutputpath>" }, "/p:PackageOutputPath=<packageoutputpath>")]
[InlineData(new string[] { "-o", "TestPackageOutputPath" }, "/p:PackageOutputPath=<cwd>TestPackageOutputPath")]
[InlineData(new string[] { "--output", "TestPackageOutputPath" }, "/p:PackageOutputPath=<cwd>TestPackageOutputPath")]
[InlineData(new string[] { "--no-build" }, "/p:NoBuild=true")]
[InlineData(new string[] { "--include-symbols" }, "/p:IncludeSymbols=true")]
[InlineData(new string[] { "--include-source" }, "/p:IncludeSource=true")]
Expand All @@ -31,6 +32,7 @@ public class GivenDotnetPackInvocation
public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs)
{
expectedAdditionalArgs = (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}");
expectedAdditionalArgs = expectedAdditionalArgs.Replace("<cwd>", Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar);

var msbuildPath = "<msbuildpath>";
PackCommand.FromArgs(args, msbuildPath)
Expand Down
12 changes: 8 additions & 4 deletions test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.IO;
using FluentAssertions;
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine;
Expand All @@ -28,8 +29,8 @@ public GivenDotnetPublishInvocation(ITestOutputHelper output)
[InlineData(new string[] { "--framework", "<tfm>" }, "/p:TargetFramework=<tfm>")]
[InlineData(new string[] { "-r", "<rid>" }, "/p:RuntimeIdentifier=<rid>")]
[InlineData(new string[] { "--runtime", "<rid>" }, "/p:RuntimeIdentifier=<rid>")]
[InlineData(new string[] { "-o", "<publishdir>" }, "/p:PublishDir=<publishdir>")]
[InlineData(new string[] { "--output", "<publishdir>" }, "/p:PublishDir=<publishdir>")]
[InlineData(new string[] { "-o", "TestPublishDir" }, "/p:PublishDir=<cwd>TestPublishDir")]
[InlineData(new string[] { "--output", "TestPublishDir" }, "/p:PublishDir=<cwd>TestPublishDir")]
[InlineData(new string[] { "-c", "<config>" }, "/p:Configuration=<config>")]
[InlineData(new string[] { "--configuration", "<config>" }, "/p:Configuration=<config>")]
[InlineData(new string[] { "--version-suffix", "<versionsuffix>" }, "/p:VersionSuffix=<versionsuffix>")]
Expand All @@ -41,6 +42,7 @@ public GivenDotnetPublishInvocation(ITestOutputHelper output)
public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs)
{
expectedAdditionalArgs = (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}");
expectedAdditionalArgs = expectedAdditionalArgs.Replace("<cwd>", Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar);

var msbuildPath = "<msbuildpath>";
PublishCommand.FromArgs(args, msbuildPath)
Expand All @@ -55,8 +57,8 @@ public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalA
[InlineData(new string[] { "--framework", "<tfm>" }, "/p:TargetFramework=<tfm>")]
[InlineData(new string[] { "-r", "<rid>" }, "/p:RuntimeIdentifier=<rid>")]
[InlineData(new string[] { "--runtime", "<rid>" }, "/p:RuntimeIdentifier=<rid>")]
[InlineData(new string[] { "-o", "<publishdir>" }, "/p:PublishDir=<publishdir>")]
[InlineData(new string[] { "--output", "<publishdir>" }, "/p:PublishDir=<publishdir>")]
[InlineData(new string[] { "-o", "TestPublishDir" }, "/p:PublishDir=<cwd>TestPublishDir")]
[InlineData(new string[] { "--output", "TestPublishDir" }, "/p:PublishDir=<cwd>TestPublishDir")]
[InlineData(new string[] { "-c", "<config>" }, "/p:Configuration=<config>")]
[InlineData(new string[] { "--configuration", "<config>" }, "/p:Configuration=<config>")]
[InlineData(new string[] { "--version-suffix", "<versionsuffix>" }, "/p:VersionSuffix=<versionsuffix>")]
Expand All @@ -65,6 +67,8 @@ public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalA
[InlineData(new string[] { "--verbosity", "minimal" }, "/verbosity:minimal")]
public void OptionForwardingIsCorrect(string[] args, string expectedAdditionalArgs)
{
expectedAdditionalArgs = expectedAdditionalArgs.Replace("<cwd>", Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar);

var expectedArgs = expectedAdditionalArgs.Split(' ', StringSplitOptions.RemoveEmptyEntries);

var parser = Parser.Instance;
Expand Down