diff --git a/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsi/FsiCliTests.fs b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsi/FsiCliTests.fs index dbb08a42edb..2f96d57d663 100644 --- a/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsi/FsiCliTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsi/FsiCliTests.fs @@ -85,10 +85,28 @@ module FsiCliTests = finally try System.IO.File.Delete(scriptPath) with _ -> () + // The FSI #r "nuget:" restore below must request a package version that is guaranteed to be in + // the offline restore cache on the internal signed build (which cannot restore online). Central + // package management + transitive pinning means only the centrally-pinned version (eng/Packages.props) + // is ever restored into that cache, and it changes whenever the pin is bumped. Rather than hardcode + // a version that would silently drift, read the exact pinned version baked into this test assembly + // at build time via AssemblyMetadata (see FSharp.Compiler.ComponentTests.fsproj). The package id + // (MessagePack) is kept in sync with that project; any centrally-pinned standalone package would do. + [] + let private restoreTestPackageId = "MessagePack" + + let private restoreTestPackageVersion = + System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(typeof, false) + |> Array.tryPick (fun a -> + let m = a :?> System.Reflection.AssemblyMetadataAttribute + if m.Key = "FsiRestoreTestPackageVersion" && not (System.String.IsNullOrWhiteSpace m.Value) then Some m.Value else None) + |> Option.defaultWith (fun () -> + failwith "AssemblyMetadata 'FsiRestoreTestPackageVersion' is missing. It should be emitted by FSharp.Compiler.ComponentTests.fsproj from the central MessagePack PackageVersion.") + [] let ``FSI quiet mode suppresses NuGet restore output from stdout`` () = - let script = """ -#r "nuget: Newtonsoft.Json, 13.0.3" + let script = $""" +#r "nuget: {restoreTestPackageId}, {restoreTestPackageVersion}" printfn "RESULT_MARKER_18086" """ let result = runFsiScript ["--quiet"] script @@ -100,8 +118,8 @@ printfn "RESULT_MARKER_18086" [] let ``FSI default (non-quiet) mode still evaluates script and prints user output`` () = - let script = """ -#r "nuget: Newtonsoft.Json, 13.0.3" + let script = $""" +#r "nuget: {restoreTestPackageId}, {restoreTestPackageVersion}" printfn "RESULT_MARKER_18086_DEFAULT" """ let result = runFsiScript [] script diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 9552df0463c..476b903efcf 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -562,5 +562,20 @@ + + + @(PackageVersion->WithMetadataValue('Identity','MessagePack')->'%(Version)') + + + +