Skip to content

Commit 1008a86

Browse files
Merge branch 'master' into patch-1
2 parents 76ca18f + c5f6b7d commit 1008a86

File tree

8 files changed

+144
-112
lines changed

8 files changed

+144
-112
lines changed

docs/guide/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ the dependency we specified (FAKE's target module). Paket has a
9999
After configuring Paket, you are ready to run your script. Enter the following command to do so:
100100

101101
```shell
102-
dotnet si build.fsx --compilertool:"~/.nuget/packages/fsharp.dependencymanager.paket/6.0.0-alpha055/lib/netstandard2.0"
102+
dotnet fsi build.fsx --compilertool:"~/.nuget/packages/fsharp.dependencymanager.paket/6.0.0-alpha055/lib/netstandard2.0"
103103
```
104104

105105

global.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"sdk" : {
3-
"version": "6.0.101"
3+
"version": "6.0.101",
4+
"rollForward": "latestMinor"
45
}
56
}

paket.dependencies

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ group fakerunner
2525
nuget FSharp.Core
2626
nuget FSharp.Compiler.Service
2727
nuget Microsoft.Deployment.DotNet.Releases
28+
nuget NuGet.Packaging
2829
nuget Paket.Core
2930
nuget Mono.Cecil
3031
nuget Microsoft.NETCore.App framework: netstandard1.6, netstandard2.0, netcoreapp1.1

paket.lock

Lines changed: 68 additions & 56 deletions
Large diffs are not rendered by default.

src/app/Fake.BuildServer.AppVeyor/AppVeyorInternal.fs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ module internal AppVeyorInternal =
5353
// because otherwise there might be recursive failure...
5454
eprintfn "AppVeyor 'AddMessage' failed: %O" e
5555

56-
let internal quoteString str =
57-
StringBuilder()
58-
|> StringBuilder.appendQuotedIfNotNull Some str
59-
|> StringBuilder.toText
56+
/// quote and escape the single argument, if required.
57+
let private quoteString str = Args.toWindowsCommandLine [ str ]
6058

6159
/// Starts the test case.
6260
let StartTestCase testSuiteName testCaseName =

src/app/Fake.Core.Process/CmdLineParsing.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ type FilePath = string
140140
module Args =
141141
/// <summary>
142142
/// Convert the given argument list to a conforming windows command line string, escapes parameter in quotes if
143-
/// needed (currently always but this might change).
143+
/// needed.
144144
/// </summary>
145145
///
146146
/// <param name="args">The arguments list</param>

src/app/Fake.DotNet.Cli/DotNet.fs

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,13 @@ module DotNet =
6666
let content = File.ReadAllText globalJson.FullName
6767
let json = JObject.Parse content
6868
let sdk = json.Item("sdk") :?> JObject
69-
let version = sdk.Property("version").Value.ToString()
70-
Some version
69+
70+
match sdk.Property("version") with
71+
| null -> None
72+
| version ->
73+
let versionValue = version.Value.ToString()
74+
let _ = Version.Parse(versionValue)
75+
Some versionValue
7176
with exn ->
7277
failwithf "Could not parse `sdk.version` from global.json at '%s': %s" globalJson.FullName exn.Message
7378

@@ -774,6 +779,22 @@ module DotNet =
774779

775780
run cmdArgs options
776781

782+
/// <summary>
783+
/// Execute raw dotnet cli command.
784+
/// Similar to 'exec' but takes a string list instead of a single string.
785+
/// </summary>
786+
///
787+
/// <param name="buildOptions">build common execution options</param>
788+
/// <param name="command">the sdk command to execute <c>test</c>, <c>new</c>, <c>build</c>, ...</param>
789+
/// <param name="args">command arguments</param>
790+
let private execArgsList (buildOptions: Options -> Options) (command: string) (args: string list) =
791+
let options = setOptions buildOptions
792+
793+
let cmdArgs =
794+
buildCommand (command |> Args.fromWindowsCommandLine |> Seq.toList) args options
795+
796+
run cmdArgs options
797+
777798
/// <summary>
778799
/// Replace the current <c>CreateProcess</c> instance to run with dotnet.exe
779800
/// </summary>
@@ -1130,7 +1151,7 @@ module DotNet =
11301151
// used for detection
11311152
let callMsBuildExe args =
11321153
let result =
1133-
exec
1154+
execArgsList
11341155
(fun _ ->
11351156
{ RedirectOutput = true
11361157
PrintRedirectedOutput = true
@@ -1153,21 +1174,21 @@ module DotNet =
11531174
MSBuild.addBinaryLogger (common.DotNetCliPath + " msbuild") callMsBuildExe args disableFakeBinLog
11541175

11551176
let internal execWithBinLog project common command args msBuildArgs =
1156-
let argString = MSBuild.fromCliArguments msBuildArgs
1177+
let msbuildArgList = MSBuild.fromCliArguments msBuildArgs
11571178

11581179
let binLogPath, args =
1159-
addBinaryLogger msBuildArgs.DisableInternalBinLog (args + " " + argString) common
1180+
addBinaryLogger msBuildArgs.DisableInternalBinLog (args @ msbuildArgList) common
11601181

1161-
let result = exec (fun _ -> common) command args
1182+
let result = execArgsList (fun _ -> common) command args
11621183
MSBuild.handleAfterRun (sprintf "dotnet %s" command) binLogPath result.ExitCode project
11631184

11641185
let internal tryExecWithBinLog project common command args msBuildArgs =
1165-
let argString = MSBuild.fromCliArguments msBuildArgs
1186+
let msbuildArgList = MSBuild.fromCliArguments msBuildArgs
11661187

11671188
let binLogPath, args =
1168-
addBinaryLogger msBuildArgs.DisableInternalBinLog (args + " " + argString) common
1189+
addBinaryLogger msBuildArgs.DisableInternalBinLog (args @ msbuildArgList) common
11691190

1170-
let result = exec (fun _ -> common) command args
1191+
let result = execArgsList (fun _ -> common) command args
11711192

11721193
try
11731194
MSBuild.handleAfterRun (sprintf "dotnet %s" command) binLogPath result.ExitCode project
@@ -1209,7 +1230,6 @@ module DotNet =
12091230

12101231
let param = MSBuildOptions.Create() |> setParams
12111232
let args = [ project ]
1212-
let args = Args.toWindowsCommandLine args
12131233
execWithBinLog project param.Common "msbuild" args param.MSBuildParams
12141234
__.MarkSuccess()
12151235

@@ -1219,7 +1239,6 @@ module DotNet =
12191239

12201240
let param = MSBuildOptions.Create() |> setParams
12211241
let args = [ project ]
1222-
let args = Args.toWindowsCommandLine args
12231242
let r = tryExecWithBinLog project param.Common "msbuild" args param.MSBuildParams
12241243
//__.MarkSuccess()
12251244
r
@@ -1306,7 +1325,7 @@ module DotNet =
13061325
let restore setParams project =
13071326
use __ = Trace.traceTask "DotNet:restore" project
13081327
let param = RestoreOptions.Create() |> setParams
1309-
let args = Args.toWindowsCommandLine (project :: buildRestoreArgs param)
1328+
let args = project :: buildRestoreArgs param
13101329
execWithBinLog project param.Common "restore" args param.MSBuildParams
13111330
__.MarkSuccess()
13121331

@@ -1443,7 +1462,7 @@ module DotNet =
14431462
let pack setParams project =
14441463
use __ = Trace.traceTask "DotNet:pack" project
14451464
let param = PackOptions.Create() |> setParams
1446-
let args = Args.toWindowsCommandLine (project :: buildPackArgs param)
1465+
let args = project :: buildPackArgs param
14471466
execWithBinLog project param.Common "pack" args param.MSBuildParams
14481467
__.MarkSuccess()
14491468

@@ -1560,7 +1579,7 @@ module DotNet =
15601579
let publish setParams project =
15611580
use __ = Trace.traceTask "DotNet:publish" project
15621581
let param = PublishOptions.Create() |> setParams
1563-
let args = Args.toWindowsCommandLine (project :: buildPublishArgs param)
1582+
let args = project :: buildPublishArgs param
15641583
execWithBinLog project param.Common "publish" args param.MSBuildParams
15651584
__.MarkSuccess()
15661585

@@ -1650,7 +1669,7 @@ module DotNet =
16501669
let build setParams project =
16511670
use __ = Trace.traceTask "DotNet:build" project
16521671
let param = BuildOptions.Create() |> setParams
1653-
let args = Args.toWindowsCommandLine (project :: buildBuildArgs param)
1672+
let args = project :: buildBuildArgs param
16541673
execWithBinLog project param.Common "build" args param.MSBuildParams
16551674
__.MarkSuccess()
16561675

@@ -1801,7 +1820,7 @@ module DotNet =
18011820
let test setParams project =
18021821
use __ = Trace.traceTask "DotNet:test" project
18031822
let param = TestOptions.Create() |> setParams
1804-
let args = Args.toWindowsCommandLine (project :: buildTestArgs param)
1823+
let args = project :: buildTestArgs param
18051824
execWithBinLog project param.Common "test" args param.MSBuildParams
18061825
__.MarkSuccess()
18071826

@@ -1868,8 +1887,8 @@ module DotNet =
18681887
pushParams.SymbolApiKey
18691888
|> Option.iter (fun key -> TraceSecrets.register "<SymbolApiKey>" key)
18701889

1871-
let args = Args.toWindowsCommandLine (nupkg :: buildNugetPushArgs pushParams)
1872-
let result = exec (fun _ -> param.Common) "nuget push" args
1890+
let args = nupkg :: buildNugetPushArgs pushParams
1891+
let result = execArgsList (fun _ -> param.Common) "nuget push" args
18731892

18741893
if result.OK then
18751894
__.MarkSuccess()
@@ -1991,8 +2010,8 @@ module DotNet =
19912010
let newFromTemplate templateName setParams =
19922011
use __ = Trace.traceTask "DotNet:new" "dotnet new command"
19932012
let param = NewOptions.Create() |> setParams
1994-
let args = Args.toWindowsCommandLine (buildNewArgs param)
1995-
let result = exec (fun _ -> param.Common) $"new {templateName}" args
2013+
let args = buildNewArgs param
2014+
let result = execArgsList (fun _ -> param.Common) $"new {templateName}" args
19962015

19972016
if not result.OK then
19982017
failwithf $"dotnet new failed with code %i{result.ExitCode}"
@@ -2008,8 +2027,8 @@ module DotNet =
20082027
let installTemplate templateName setParams =
20092028
use __ = Trace.traceTask "DotNet:new" "dotnet new --install command"
20102029
let param = TemplateInstallOptions.Create(templateName) |> setParams
2011-
let args = Args.toWindowsCommandLine (buildTemplateInstallArgs param)
2012-
let result = exec (fun _ -> param.Common) "new" args
2030+
let args = buildTemplateInstallArgs param
2031+
let result = execArgsList (fun _ -> param.Common) "new" args
20132032

20142033
if not result.OK then
20152034
failwithf $"dotnet new --install failed with code %i{result.ExitCode}"
@@ -2025,8 +2044,8 @@ module DotNet =
20252044
let uninstallTemplate templateName =
20262045
use __ = Trace.traceTask "DotNet:new" "dotnet new --uninstall command"
20272046
let param = TemplateUninstallOptions.Create(templateName)
2028-
let args = Args.toWindowsCommandLine (buildTemplateUninstallArgs param)
2029-
let result = exec (fun _ -> param.Common) "new" args
2047+
let args = buildTemplateUninstallArgs param
2048+
let result = execArgsList (fun _ -> param.Common) "new" args
20302049

20312050
// If the process returns error (exit code != 0) then check to see if a message is
20322051
// that the template was not found. If this message exists, assume the process

src/app/Fake.DotNet.MSBuild/MSBuild.fs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -686,11 +686,6 @@ module MSBuild =
686686

687687
a, fileName |> Path.getFullName)
688688

689-
let internal quoteString str =
690-
StringBuilder()
691-
|> StringBuilder.appendQuotedIfNotNull Some str
692-
|> StringBuilder.toText
693-
694689
let rec private getProjectReferences (projectFileName: string) =
695690
match projectFileName.EndsWith ".sln" with
696691
| true -> Set.empty
@@ -877,24 +872,31 @@ module MSBuild =
877872
yield! properties ]
878873
|> Seq.choose id
879874
|> Seq.map (fun (k, v) -> "/" + k + (if String.isNullOrEmpty v then "" else ":" + v))
880-
|> Args.toWindowsCommandLine
875+
|> Seq.toList
881876

882877
/// [omit]
883-
let buildArgs (setParams: MSBuildParams -> MSBuildParams) =
878+
let buildArgs (setParams: MSBuildParams -> MSBuildParams) : MSBuildParams * string =
879+
let p = MSBuildParams.Create() |> setParams
880+
p, fromCliArguments p.CliArguments |> Args.toWindowsCommandLine
881+
882+
/// <summary>
883+
/// similar to 'buildArgs' but returns a string list instead of a single string for the arguments
884+
/// </summary>
885+
let private buildArgsToList (setParams: MSBuildParams -> MSBuildParams) : MSBuildParams * string list =
884886
let p = MSBuildParams.Create() |> setParams
885887
p, fromCliArguments p.CliArguments
886888

887889

888890
let internal getVersion =
889891
let cache = System.Collections.Concurrent.ConcurrentDictionary<string, Version>()
890892

891-
fun (exePath: string) (callMsbuildExe: string -> string) ->
893+
fun (exePath: string) (callMsbuildExe: string list -> string) ->
892894
let getFromCall () =
893895
try
894896
let result =
895897
match Environment.isUnix with
896-
| true -> callMsbuildExe "--version --nologo"
897-
| false -> callMsbuildExe "/version /nologo"
898+
| true -> callMsbuildExe [ "--version"; "--nologo" ]
899+
| false -> callMsbuildExe [ "/version"; "/nologo" ]
898900

899901
let line =
900902
if result.Contains "DOTNET_CLI_TELEMETRY_OPTOUT" then
@@ -914,23 +916,23 @@ module MSBuild =
914916

915917
let internal addBinaryLogger
916918
(exePath: string)
917-
(callMsbuildExe: string -> string)
918-
(args: string)
919+
(callMsbuildExe: string list -> string)
920+
(args: string list)
919921
(disableFakeBinLogger: bool)
920922
=
921923
#if !NO_MSBUILD_BINLOG
922924
if disableFakeBinLogger then
923925
None, args
924926
else
925-
let argList = Args.fromWindowsCommandLine args |> Seq.toList
927+
let argList = args |> Seq.toList
926928
let path = Path.GetTempFileName()
927929
File.Delete(path)
928930
let path = path + ".binlog"
929931
//let path = Path.GetFullPath <| sprintf "fake-msbuild-%s.binlog" (System.Guid.NewGuid().ToString())
930932
let v = getVersion exePath callMsbuildExe
931933

932934
if v >= versionToUseBinLog then
933-
Some path, Args.toWindowsCommandLine (argList @ [ "/bl:" + path ])
935+
Some path, (argList @ [ "/bl:" + path ])
934936
elif v >= versionToUseStructuredLogger then
935937
let assemblyPath =
936938
let currentPath = MSBuildBinLog.structuredLogAssemblyPath
@@ -941,8 +943,7 @@ module MSBuild =
941943
else
942944
Path.Combine(libFolder, "net46", "StructuredLogger.dll")
943945

944-
Some path,
945-
Args.toWindowsCommandLine (argList @ [ sprintf "/logger:BinaryLogger,%s;%s" assemblyPath path ])
946+
Some path, (argList @ [ sprintf "/logger:BinaryLogger,%s;%s" assemblyPath path ])
946947
else
947948
Trace.traceFAKE
948949
"msbuild version '%O' doesn't support binary logger, please set the msbuild argument 'DisableInternalBinLog' to 'true' to disable this warning."
@@ -998,7 +999,7 @@ module MSBuild =
998999
let messageF msg = results.Add msg
9991000

10001001
let processResult =
1001-
CreateProcess.fromRawCommandLine msBuildParams.ToolPath args
1002+
CreateProcess.fromRawCommand msBuildParams.ToolPath args
10021003
|> CreateProcess.withTimeout TimeSpan.MaxValue
10031004
|> CreateProcess.withEnvironment (msBuildParams.Environment |> Map.toList)
10041005
|> CreateProcess.redirectOutput
@@ -1017,9 +1018,9 @@ module MSBuild =
10171018
/// <param name="setParams">A function that overwrites the default MSBuildParams</param>
10181019
/// <param name="project">A string with the path to the project file to build.</param>
10191020
let buildWithRedirect setParams project =
1020-
let msBuildParams, argsString = buildArgs setParams
1021+
let msBuildParams, argsList = buildArgsToList setParams
10211022

1022-
let args = quoteString (project + " " + argsString)
1023+
let args = project :: argsList
10231024

10241025
let binlogPath, args =
10251026
addBinaryLogger
@@ -1034,7 +1035,7 @@ module MSBuild =
10341035
else
10351036
sprintf "%s>" msBuildParams.WorkingDirectory
10361037

1037-
Trace.tracefn "%s%s %s" wd msBuildParams.ToolPath args
1038+
Trace.tracefn "%s%s %s" wd msBuildParams.ToolPath (Args.toWindowsCommandLine args)
10381039

10391040
let results = System.Collections.Generic.List<ConsoleMessage>()
10401041

@@ -1045,7 +1046,7 @@ module MSBuild =
10451046
results.Add(ConsoleMessage.CreateOut msg)
10461047

10471048
let processResult =
1048-
CreateProcess.fromRawCommandLine msBuildParams.ToolPath args
1049+
CreateProcess.fromRawCommand msBuildParams.ToolPath args
10491050
|> CreateProcess.withTimeout TimeSpan.MaxValue
10501051
|> CreateProcess.withEnvironment (msBuildParams.Environment |> Map.toList)
10511052
|> CreateProcess.withWorkingDirectory msBuildParams.WorkingDirectory
@@ -1086,9 +1087,9 @@ module MSBuild =
10861087
/// </example>
10871088
let build setParams project =
10881089
use __ = Trace.traceTask "MSBuild" project
1089-
let msBuildParams, argsString = buildArgs setParams
1090+
let msBuildParams, argsList = buildArgsToList setParams
10901091

1091-
let args = quoteString (project + " " + argsString)
1092+
let args = project :: argsList
10921093

10931094
let binlogPath, args =
10941095
addBinaryLogger
@@ -1103,10 +1104,10 @@ module MSBuild =
11031104
else
11041105
sprintf "%s>" msBuildParams.WorkingDirectory
11051106

1106-
Trace.tracefn "%s%s %s" wd msBuildParams.ToolPath args
1107+
Trace.tracefn "%s%s %s" wd msBuildParams.ToolPath (Args.toWindowsCommandLine args)
11071108

11081109
let processResult =
1109-
CreateProcess.fromRawCommandLine msBuildParams.ToolPath args
1110+
CreateProcess.fromRawCommand msBuildParams.ToolPath args
11101111
|> CreateProcess.withWorkingDirectory msBuildParams.WorkingDirectory
11111112
|> CreateProcess.withTimeout TimeSpan.MaxValue
11121113
|> CreateProcess.withEnvironment (msBuildParams.Environment |> Map.toList)

0 commit comments

Comments
 (0)