anchor.diff:                      (fun _ -> ()), defaultToDotNetFramework, 
                       tcConfigB.tryGetMetadataSnapshot, tcConfigB.reduceMemoryUsage, dependencyProvider)
   
  -            // Record the references from the analysis of the script.
  -            let references = loadClosure.References |> List.collect snd
  +            // Record the new references (non-framework) references from the analysis of the script. (The full resolutions are recorded
  +            // as the corresponding #I paths used to resolve them are local to the scripts and not added to the tcConfigB - they are
  +            // added to localized clones of the tcConfigB).
  +            let references =
  +                loadClosure.References
  +                |> List.collect snd
  +                |> List.filter (fun r -> not (Range.equals r.originalReference.Range range0) && not (Range.equals r.originalReference.Range rangeStartup))
   
               references |> List.iter (fun r -> tcConfigB.AddReferencedAssemblyByPath(r.originalReference.Range, r.resolvedPath))
  +
  +            // Also record the other declarations from the script.
               loadClosure.NoWarns |> List.collect (fun (n, ms) -> ms|>List.map(fun m->m, n)) |> List.iter (fun (x,m) -> tcConfigB.TurnWarningOff(x, m))
               loadClosure.SourceFiles |> List.map fst |> List.iter AddIfNotPresent
               loadClosure.AllRootFileDiagnostics |> List.iter diagnosticSink
  -            tcConfigB.inferredTargetFrameworkForScripts <- Some loadClosure.InferredTargetFramework
  -            tcConfigB.primaryAssembly <- loadClosure.InferredTargetFramework.InferredFramework.PrimaryAssembly
  -            tcConfigB.fxResolver <- FxResolver(tcConfigB.reduceMemoryUsage, tcConfigB.tryGetMetadataSnapshot, Some loadClosure.InferredTargetFramework.UseDotNetFramework)
  +
  +            // If there was an explicit #targetfx in the script then push that as a requirement into the overall compilation and add all the framework references implied
  +            // by the script too.
  +            match loadClosure.InferredTargetFramework.WhereInferred with
  +            | Some m ->
  +                tcConfigB.CheckExplicitFrameworkDirective(loadClosure.InferredTargetFramework.InferredFramework, m)
  +                tcConfigB.primaryAssembly <- loadClosure.InferredTargetFramework.InferredFramework.PrimaryAssembly
  +                tcConfigB.fxResolver <- FxResolver(tcConfigB.reduceMemoryUsage, tcConfigB.tryGetMetadataSnapshot, Some loadClosure.InferredTargetFramework.UseDotNetFramework)
  +                if tcConfigB.framework then
  +                    let references = loadClosure.References |> List.collect snd
  +                    references |> List.iter (fun r -> tcConfigB.AddReferencedAssemblyByPath(r.originalReference.Range, r.resolvedPath))
  +            | None -> ()
               
           else AddIfNotPresent filename
            
  
positive.code:         exiter.Exit 1
  
  /// Check for .fsx and, if present, compute the load closure for of #loaded files.
  let AdjustForScriptCompile(ctok, tcConfigB: TcConfigBuilder, defaultToDotNetFramework, commandLineSourceFiles, dependencyProvider) =
  
      let combineFilePath file =
  
negative.code:             allSources <- filename :: allSources
      
      let AppendClosureInformation filename =
          if IsScript filename then 
  
              // Get the source to infer the target framework from any #targetfx declarations in the script
              let source = SourceText.ofString (File.ReadAllText filename)
  
              // Do we assume .NET Framework references for scripts? In the absence of either explicit argument
              // or an explicit #targetfx declaration, then for compilation and analysis the default
  