@@ -1774,7 +1774,25 @@ let OutputDiagnosticContext prefix fileLineFn os err =
17741774let GetFSharpCoreLibraryName () = " FSharp.Core"
17751775
17761776// If necessary assume a reference to the latest .NET Framework FSharp.Core with which those tools are built.
1777- let GetDefaultFSharpCoreReference () = typeof< list< int>>. Assembly.Location
1777+ let GetDefaultFSharpCoreReference () = typeof< list< int>>. Assembly.Location
1778+
1779+ type private TypeInThisAssembly = class end
1780+
1781+ // Use the ValueTuple that is executing with the compiler if it is from System.ValueTuple
1782+ // or the System.ValueTuple.dll that sits alongside the compiler. (Note we always ship one with the compiler)
1783+ let GetDefaultSystemValueTupleReference () =
1784+ try
1785+ let asm = typeof< System.ValueTuple< int, int>>. Assembly
1786+ if asm.FullName.StartsWith" System.ValueTuple" then
1787+ Some asm.Location
1788+ else
1789+ let location = Path.GetDirectoryName( typeof< TypeInThisAssembly>. Assembly.Location)
1790+ let valueTuplePath = Path.Combine( location, " System.ValueTuple.dll" )
1791+ if File.Exists( valueTuplePath) then
1792+ Some valueTuplePath
1793+ else
1794+ None
1795+ with _ -> None
17781796
17791797let GetFsiLibraryName () = " FSharp.Compiler.Interactive.Settings"
17801798
@@ -1808,10 +1826,11 @@ let DefaultReferencesForScriptsAndOutOfProjectSources(assumeDotNetFramework) =
18081826yield " System.Collections" // System.Collections.Generic.List<T>
18091827yield " System.Runtime.Numerics" // BigInteger
18101828yield " System.Threading" // OperationCanceledException
1811- #if ! COMPILER_ SERVICE_ AS_ DLL
1812- // TODO, right now FCS doesn't add this reference automatically
1813- yield " System.ValueTuple"
1814- #endif
1829+
1830+ // always include a default reference to System.ValueTuple.dll in scripts and out-of-project sources
1831+ match GetDefaultSystemValueTupleReference() with
1832+ | None-> ()
1833+ | Some v-> yield v
18151834
18161835yield " System.Web"
18171836yield " System.Web.Services"