Skip to content

Commit e06abd0

Browse files
committed
Workaround for Mono 4.2 changes to xbuild
1 parent d54f3fa commit e06abd0

File tree

1 file changed

+21
-5
lines changed
  • src/fsharp/FSharp.Compiler.Service.ProjectCracker.Exe

1 file changed

+21
-5
lines changed

src/fsharp/FSharp.Compiler.Service.ProjectCracker.Exe/Program.fs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ module Program =
5757
// Use the old API on Mono, with ToolsVersion = 12.0
5858
let CrackProjectUsingOldBuildAPI(fsprojFile:string) =
5959
let engine = new Microsoft.Build.BuildEngine.Engine()
60-
try
61-
engine.DefaultToolsVersion <- "12.0"
62-
with | _ -> engine.DefaultToolsVersion <- "4.0"
63-
6460
Option.iter (fun l -> engine.RegisterLogger(l)) logOpt
6561

6662
let bpg = Microsoft.Build.BuildEngine.BuildPropertyGroup()
@@ -365,8 +361,28 @@ module Program =
365361
| Some outFile, opts -> yield outFile, opts
366362
| None, _ -> () |]
367363

364+
// Workaround for Mono 4.2, which doesn't populate the subproject
365+
// details anymore outside of a solution context. See https://github.com/mono/mono/commit/76c6a08e730393927b6851709cdae1d397cbcc3a#diff-59afd196a55d61d5d1eaaef7bd49d1e5
366+
// and some explanation from the author at https://github.com/fsharp/FSharp.Compiler.Service/pull/455#issuecomment-154103963
367+
//
368+
// In particular we want the output path, which we can get from
369+
// fully parsing that project itself. We also have to specially parse
370+
// C# referenced projects, as we don't look at them otherwise.
371+
let referencedProjectOutputs =
372+
if runningOnMono then
373+
[| yield! Array.map (fun (s,_) -> "-r:" + s) referencedProjectOptions
374+
for file in parsedProject.ProjectReferences do
375+
if Path.GetExtension(file) = ".csproj" then
376+
let parsedProject = FSharpProjectFileInfo.Parse(file, properties=properties, enableLogging=false)
377+
match parsedProject.OutputFile with
378+
| None -> ()
379+
| Some f -> yield "-r:" + f |]
380+
else
381+
[||]
382+
368383
let options = { ProjectFile = file
369-
Options = Array.ofList parsedProject.Options
384+
Options = Array.append (Array.ofList (parsedProject.Options))
385+
referencedProjectOutputs
370386
ReferencedProjectOptions = referencedProjectOptions
371387
LogOutput = parsedProject.LogOutput }
372388

0 commit comments

Comments
 (0)