Skip to content

Commit 8afe8d6

Browse files
committed
Take <UseArtifactsOutput> into account during the project restore check.
1 parent 964ed92 commit 8afe8d6

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

RELEASE_NOTES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 20.0.0-alpha-011 - 2023-11-16
4+
5+
### Fixed
6+
* Take `<UseArtifactsOutput>` into account during the project restore check.
7+
38
## 20.0.0-alpha-010 - 2023-11-15
49

510
### Fixed

src/fsdocs-tool/ProjectCracker.fs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace fsdocs
22

33
open System
4+
open System.Diagnostics
45
open System.IO
56
open System.Runtime.InteropServices
67
open System.Runtime.Serialization
@@ -142,6 +143,22 @@ module Utils =
142143
else
143144
s + "/"
144145

146+
module DotNetCli =
147+
148+
/// Run `dotnet msbuild <args>` and receive the trimmed standard output.
149+
let msbuild (pwd: string) (args: string) : string =
150+
let psi = ProcessStartInfo "dotnet"
151+
psi.WorkingDirectory <- pwd
152+
psi.Arguments <- $"msbuild %s{args}"
153+
psi.RedirectStandardOutput <- true
154+
psi.UseShellExecute <- false
155+
use ps = new Process()
156+
ps.StartInfo <- psi
157+
ps.Start() |> ignore
158+
let output = ps.StandardOutput.ReadToEnd()
159+
ps.WaitForExit()
160+
output.Trim()
161+
145162
module Crack =
146163

147164
let (|ConditionEquals|_|) (str: string) (arg: string) =
@@ -337,14 +354,26 @@ module Crack =
337354
Ok(targetFrameworks, projOptions2)
338355
| Error err -> GetProjectOptionsErrors(string err, msgs) |> Result.Error
339356

340-
let crackProjectFile slnDir extraMsbuildProperties (file: string) : CrackedProjectInfo =
341-
357+
let private ensureProjectWasRestored (file: string) =
342358
let projDir = Path.GetDirectoryName(file)
343-
344359
let projectAssetsJsonPath = Path.Combine(projDir, "obj", "project.assets.json")
345360

346-
if not (File.Exists(projectAssetsJsonPath)) then
347-
failwithf "project '%s' not restored" file
361+
if File.Exists projectAssetsJsonPath then
362+
()
363+
else
364+
// In dotnet 8 <UseArtifactsOutput> was introduced, see https://learn.microsoft.com/en-us/dotnet/core/sdk/artifacts-output
365+
// We will try and use CLI-based project evaluation to determine the location of project.assets.json file
366+
// See https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-8#cli-based-project-evaluation
367+
try
368+
let path = DotNetCli.msbuild projDir "--getProperty:ProjectAssetsFile"
369+
370+
if not (File.Exists path) then
371+
failwithf $"project '%s{file}' not restored"
372+
with ex ->
373+
failwithf $"Failed to detect if the project '%s{file}' was restored"
374+
375+
let crackProjectFile slnDir extraMsbuildProperties (file: string) : CrackedProjectInfo =
376+
ensureProjectWasRestored file
348377

349378
let result = crackProjectFileAndIncludeTargetFrameworks slnDir extraMsbuildProperties file
350379
//printfn "msgs = %A" msgs

0 commit comments

Comments
 (0)