@@ -55,7 +55,6 @@ module internal Program =
5555 else
5656 None
5757
58- // Use the old API on Mono, with ToolsVersion = 12.0
5958 let CrackProjectUsingOldBuildAPI ( fsprojFile : string ) =
6059 let engine = new Microsoft.Build.BuildEngine.Engine()
6160 Option.iter ( fun l -> engine.RegisterLogger( l)) logOpt
@@ -108,6 +107,22 @@ module internal Program =
108107
109108 outFileOpt, directory, getItems, references, projectReferences, getProp project, project.FullFileName
110109
110+ let vs =
111+ let programFiles =
112+ let getEnv v =
113+ let result = System.Environment.GetEnvironmentVariable( v)
114+ match result with
115+ | null -> None
116+ | _ -> Some result
117+
118+ match List.tryPick getEnv [ " ProgramFiles(x86)" ; " ProgramFiles" ] with
119+ | Some r -> r
120+ | None -> " C:\\ Program Files (x86)"
121+
122+ let vsVersions = [ " 14.0" ; " 12.0" ]
123+ let msbuildBin v = IO.Path.Combine( programFiles, " MSBuild" , v, " Bin" , " MSBuild.exe" )
124+ List.tryFind ( fun v -> IO.File.Exists( msbuildBin v)) vsVersions
125+
111126 let CrackProjectUsingNewBuildAPI ( fsprojFile ) =
112127 let fsprojFullPath = try Path.GetFullPath( fsprojFile) with _ -> fsprojFile
113128 let fsprojAbsDirectory = Path.GetDirectoryName fsprojFullPath
@@ -128,7 +143,10 @@ module internal Program =
128143 let project = engine.LoadProject( xmlReader, FullPath= fsprojFullPath)
129144
130145 project.SetGlobalProperty( " BuildingInsideVisualStudio" , " true" ) |> ignore
131- project.SetGlobalProperty( " VisualStudioVersion" , " 12.0" ) |> ignore
146+ if not ( List.exists ( fun ( p , _ ) -> p = " VisualStudioVersion" ) properties) then
147+ match vs with
148+ | Some version -> project.SetGlobalProperty( " VisualStudioVersion" , version) |> ignore
149+ | None -> ()
132150 project.SetGlobalProperty( " ShouldUnsetParentConfigurationAndPlatform" , " false" ) |> ignore
133151 for ( prop, value) in properties do
134152 project.SetGlobalProperty( prop, value) |> ignore
0 commit comments