@@ -8,14 +8,14 @@ open Runfs.Directives
88open Runfs.ProjectFile
99open Runfs.Dependencies
1010open Runfs.Utilities
11+ open Runfs.Build
1112
1213type RunfsError =
1314 | CaughtException of Exception
1415 | InvalidSourcePath of string
1516 | InvalidSourceDirectory of string
1617 | DirectiveError of ParseError list
17- | RestoreError of stdout : string list * stderr : string list
18- | BuildError of stdout : string list * stderr : string list
18+ | BuildError of MSBuildError
1919
2020let ThisPackageName = " Runfs"
2121let DependenciesHashFileName = " dependencies.hash"
@@ -58,11 +58,12 @@ let run (options, sourcePath, args) =
5858 let showTimings = Set.contains " time" options
5959 let verbose = Set.contains " verbose" options
6060 let noDependencyCheck = Set.contains " no-dependency-check" options
61- let withOutput = Set.contains " with-output" options
6261 let inline guardAndTime name f = guardAndTime showTimings name f
6362
63+ initMSBuild()
64+
6465 result {
65- let! fullSourcePath , fullSourceDir , artifactsDir , projectFilePath ,
66+ let! fullSourcePath , fullSourceDir , artifactsDir , virtualProjectFilePath ,
6667 savedProjectFilePath , dependenciesHashPath , sourceHashPath , dllPath =
6768 guardAndTime " creating paths" <| fun () -> result {
6869 do ! File.Exists sourcePath |> Result.requireTrue ( InvalidSourcePath sourcePath)
@@ -106,7 +107,7 @@ let run (options, sourcePath, args) =
106107 return computeDependenciesHash ( string fullSourceDir) directives
107108 }
108109
109- let! dependenciesChanged , sourceChanged , noDll = guardAndTime " computing build level" <| fun () ->
110+ let! dependenciesChanged , sourceChanged , noExecutable = guardAndTime " computing build level" <| fun () ->
110111 let dependenciesChanged =
111112 if noDependencyCheck then
112113 false
@@ -119,55 +120,37 @@ let run (options, sourcePath, args) =
119120 let noDll = not ( File.Exists dllPath)
120121 Ok ( dependenciesChanged, sourceChanged, noDll)
121122
122- if dependenciesChanged || sourceChanged || noDll then
123+ if dependenciesChanged || noExecutable then
123124 do ! guardAndTime " creating and writing project file" <| fun () ->
124125 let projectFileLines = createProjectFileLines directives fullSourcePath artifactsDir AssemblyName
125126 File.WriteAllLines( savedProjectFilePath, projectFileLines) |> Ok
127+
128+ if dependenciesChanged || sourceChanged || noExecutable then
129+ use! project = guardAndTime " creating msbuild project instance" <| fun () ->
130+ let projectFileText = File.ReadAllText savedProjectFilePath
131+ createProject verbose virtualProjectFilePath projectFileText |> Ok
132+
133+ if dependenciesChanged || noExecutable then
134+ do ! guardAndTime " running msbuild restore" <| fun () -> result {
135+ File.Delete dependenciesHashPath
136+ do ! build " restore" project |> Result.mapError BuildError
137+ }
126138
127- if dependenciesChanged || noDll then
128- do ! guardAndTime " running dotnet restore" <| fun () ->
129- File.Delete dependenciesHashPath
130- if File.Exists projectFilePath then File.Delete projectFilePath
131- File.Copy( savedProjectFilePath, projectFilePath)
132- let args = [
133- " restore"
134- if not verbose then " -v:q"
135- projectFilePath
136- ]
137- let exitCode , stdoutLines , stderrLines =
138- runCommandCollectOutput " dotnet" args fullSourceDir
139- File.Delete projectFilePath
140- if exitCode <> 0 then Error( RestoreError( stdoutLines, stderrLines)) else Ok()
141-
142- if sourceChanged || dependenciesChanged || noDll then
143- do ! guardAndTime " running dotnet build" <| fun () ->
144- if File.Exists projectFilePath then File.Delete projectFilePath
145- File.Copy( savedProjectFilePath, projectFilePath)
146- let args = [
147- " build"
148- " --no-restore"
149- " -consoleLoggerParameters:NoSummary"
150- if not verbose then " -v:q"
151- projectFilePath
152- ]
153- let exitCode , stdoutLines , stderrLines =
154- runCommandCollectOutput " dotnet" args fullSourceDir
155- File.Delete projectFilePath
156- if exitCode <> 0 then Error( BuildError( stdoutLines, stderrLines)) else Ok()
157-
158- if dependenciesChanged then
159- do ! guardAndTime " saving dependencies hash" <| fun () ->
160- File.WriteAllText( dependenciesHashPath, dependenciesHash) |> Ok
161-
162- if sourceChanged then
163- do ! guardAndTime " saving source hash" <| fun () ->
164- File.WriteAllText( sourceHashPath, sourceHash) |> Ok
139+ do ! guardAndTime " running dotnet build" <| fun () -> result {
140+ File.Delete sourceHash
141+ do ! build " build" project |> Result.mapError BuildError
142+ }
143+
144+ if dependenciesChanged then
145+ do ! guardAndTime " saving dependencies hash" <| fun () ->
146+ File.WriteAllText( dependenciesHashPath, dependenciesHash) |> Ok
147+
148+ if sourceChanged then
149+ do ! guardAndTime " saving source hash" <| fun () ->
150+ File.WriteAllText( sourceHashPath, sourceHash) |> Ok
165151
166152 let! exitCode = guardAndTime " executing program" <| fun () ->
167- if withOutput then
168- runCommandCollectOutput " dotnet" ( dllPath:: args) " ." |> Ok
169- else
170- runCommand " dotnet" ( dllPath:: args) " ." |> Ok
153+ runCommand " dotnet" ( dllPath:: args) " ." |> Ok
171154
172155 return exitCode
173156 }
0 commit comments