Skip to content

Commit

Permalink
Add SelfContained, Force and Manifest to dotnet publish, (#2307)
Browse files Browse the repository at this point in the history
Add SelfContained, Force and Manifest to dotnet publish
Dotnet publish parameters lacked self-contained param. Without it it is not possible to do publish for specific runtime without embedding the runtime. While editing it I have added two other missing params - force and manifest.
  • Loading branch information
matthid authored Apr 28, 2019
2 parents a731047 + 6a45f04 commit b7dd1f1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/app/Fake.DotNet.Cli/DotNet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,10 @@ module DotNet =
| true -> [ sprintf "--%s" name ]
| false -> []

/// [omit]
let private argOptionExplicit name value =
[ sprintf "--%s=%A" name value ]

/// [omit]
let private buildCommonArgs (param: Options) =
[ defaultArg param.CustomParams "" |> Args.fromWindowsCommandLine |> Seq.toList
Expand Down Expand Up @@ -1202,10 +1206,20 @@ module DotNet =
OutputPath: string option
/// Defines what `*` should be replaced with in version field in project.json (--version-suffix)
VersionSuffix: string option
/// Specifies one or several target manifests to use to trim the set of packages published with the app.
/// The manifest file is part of the output of the dotnet store command.
/// This option is available starting with .NET Core 2.0 SDK. (--manifest)
Manifest: string list option
/// Publish the .NET Core runtime with your application so the runtime doesn't need to be installed on the target machine.
/// The default is 'true' if a runtime identifier is specified. (--self-contained)
SelfContained: bool option
/// No build flag (--no-build)
NoBuild: bool
/// Doesn't execute an implicit restore when running the command. (--no-restore)
NoRestore: bool
/// Force all dependencies to be resolved even if the last restore was successful.
/// This is equivalent to deleting project.assets.json. (--force)
Force: bool option
/// Other msbuild specific parameters
MSBuildParams : MSBuild.CliArguments
}
Expand All @@ -1221,6 +1235,9 @@ module DotNet =
VersionSuffix = None
NoBuild = false
NoRestore = false
Force = None
SelfContained = None
Manifest = None
MSBuildParams = MSBuild.CliArguments.Create()
}
[<Obsolete("Use PublishOptions.Create instead")>]
Expand All @@ -1239,16 +1256,19 @@ module DotNet =
{ x with Common = f x.Common }

/// [omit]
let private buildPublishArgs (param: PublishOptions) =
let internal buildPublishArgs (param: PublishOptions) =
[
buildConfigurationArg param.Configuration
param.Framework |> Option.toList |> argList2 "framework"
param.Runtime |> Option.toList |> argList2 "runtime"
param.BuildBasePath |> Option.toList |> argList2 "build-base-path"
param.OutputPath |> Option.toList |> argList2 "output"
param.VersionSuffix |> Option.toList |> argList2 "version-suffix"
param.Manifest |> Option.toList |> List.collect id |> argList2 "manifest"
param.NoBuild |> argOption "no-build"
param.NoRestore |> argOption "no-restore"
param.SelfContained |> Option.map (argOptionExplicit "self-contained") |> Option.defaultValue []
param.Force |> Option.map (argOption "force") |> Option.defaultValue []
]
|> List.concat
|> List.filter (not << String.IsNullOrEmpty)
Expand Down
39 changes: 39 additions & 0 deletions src/test/Fake.Core.UnitTests/Fake.DotNet.Cli.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,44 @@ let tests =

let expected = "--disable-buffering --api-key abc123 --no-symbols --no-service-endpoint --source MyNuGetSource --symbol-api-key MySymbolApiKey --symbol-source MySymbolSource --timeout 300"

Expect.equal cli expected "Push args generated correctly."

testCase "Test that the dotnet publish self-contained works as expected" <| fun _ ->
let param =
{ DotNet.PublishOptions.Create() with
SelfContained = Some false }
let cli =
param
|> DotNet.buildPublishArgs
|> Args.toWindowsCommandLine

let expected = "--configuration Release --self-contained=false"

Expect.equal cli expected "Push args generated correctly."

testCase "Test that the dotnet publish force works as expected" <| fun _ ->
let param =
{ DotNet.PublishOptions.Create() with
Force = Some true }
let cli =
param
|> DotNet.buildPublishArgs
|> Args.toWindowsCommandLine

let expected = "--configuration Release --force"

Expect.equal cli expected "Push args generated correctly."

testCase "Test that the dotnet publish manifest works as expected" <| fun _ ->
let param =
{ DotNet.PublishOptions.Create() with
Manifest = Some ["Path1"; "Path2"] }
let cli =
param
|> DotNet.buildPublishArgs
|> Args.toWindowsCommandLine

let expected = "--configuration Release --manifest Path1 --manifest Path2"

Expect.equal cli expected "Push args generated correctly."
]

0 comments on commit b7dd1f1

Please sign in to comment.