Skip to content

Commit 942a1fd

Browse files
Repo AssistCopilot
authored andcommitted
Fix project restore detection for nonstandard artifact locations
When a project doesn't place project.assets.json under <projDir>/obj/ (e.g. UseArtifactsOutput or projects like dotnet/fsharp with custom output layout), the fallback MSBuild --getProperty call may itself fail. Previously that failure was hard-coded to throw, making it impossible to use fsdocs on such repos. Following the maintainer suggestion from issue #592, change the fallback so that: - If MSBuild succeeds and reports an assets path that exists -> OK - If MSBuild succeeds but the assets file doesn't exist -> fail fast (project definitely not restored) - If MSBuild fails (e.g. old SDK, nonstandard project) -> warn and proceed, letting the cracking step produce the definitive error Closes #592 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent cacabf3 commit 942a1fd

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* `IFsiEvaluator` now inherits `IDisposable`; `FsiEvaluator` disposes its underlying FSI session when disposed, preventing session leaks in long-running processes. [#341](https://github.com/fsprojects/FSharp.Formatting/issues/341)
1313

1414
### Fixed
15+
* Fix project restore detection for projects with nonstandard artifact locations (e.g. `<UseArtifactsOutput>` or the dotnet/fsharp repo layout): when the MSBuild call to locate `project.assets.json` fails, emit a warning and proceed instead of hard-failing. [#592](https://github.com/fsprojects/FSharp.Formatting/issues/592)
1516
* Fix doc generation failure for members with 5D/6D+ array parameters by correctly formatting array type signatures in XML doc format (e.g. `System.Double[0:,0:,0:,0:,0:]` for a 5D array). [#702](https://github.com/fsprojects/FSharp.Formatting/issues/702)
1617
* Fix `_menu_template.html` and `_menu-item_template.html` being copied to the output directory. [#803](https://github.com/fsprojects/FSharp.Formatting/issues/803)
1718
* Fix `ApiDocMember.Details.ReturnInfo.ReturnType` returning `None` for properties that have both a getter and a setter. [#734](https://github.com/fsprojects/FSharp.Formatting/issues/734)

src/fsdocs-tool/ProjectCracker.fs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,15 +372,28 @@ module Crack =
372372
()
373373
else
374374
// In dotnet 8 <UseArtifactsOutput> was introduced, see https://learn.microsoft.com/en-us/dotnet/core/sdk/artifacts-output
375-
// We will try and use CLI-based project evaluation to determine the location of project.assets.json file
375+
// We will try and use CLI-based project evaluation to determine the location of project.assets.json file.
376376
// See https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-8#cli-based-project-evaluation
377-
try
378-
let path = DotNetCli.msbuild projDir "--getProperty:ProjectAssetsFile"
377+
// Some projects (e.g. those with nonstandard artifact output locations) may not put project.assets.json
378+
// under <projDir>/obj/. If we can detect the actual path via MSBuild, we use that; otherwise we warn
379+
// and proceed so that the cracking step itself can produce the definitive error.
380+
let detectedPath =
381+
try
382+
let path = DotNetCli.msbuild projDir "--getProperty:ProjectAssetsFile"
383+
Some path
384+
with _ ->
385+
None
379386

380-
if not (File.Exists path) then
381-
failwithf $"project '%s{file}' not restored"
382-
with ex ->
383-
failwithf $"Failed to detect if the project '%s{file}' was restored"
387+
match detectedPath with
388+
| Some path when File.Exists path -> ()
389+
| Some _ ->
390+
// MSBuild reported a path but the file doesn't exist there — project is definitely not restored.
391+
failwithf $"project '%s{file}' not restored"
392+
| None ->
393+
// Could not determine the assets file location (e.g. old SDK without --getProperty support,
394+
// or nonstandard project layout). Warn and continue; if the project truly isn't restored the
395+
// subsequent cracking step will fail with a more specific error.
396+
printfn $"Warning: could not verify that project '%s{file}' was restored. Proceeding anyway."
384397

385398
let crackProjectFile slnDir extraMsbuildProperties (file: string) : CrackedProjectInfo =
386399
ensureProjectWasRestored file

0 commit comments

Comments
 (0)