@@ -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
0 commit comments