@@ -55,7 +55,6 @@ module internal Program =
55
55
else
56
56
None
57
57
58
- // Use the old API on Mono, with ToolsVersion = 12.0
59
58
let CrackProjectUsingOldBuildAPI ( fsprojFile : string ) =
60
59
let engine = new Microsoft.Build.BuildEngine.Engine()
61
60
Option.iter ( fun l -> engine.RegisterLogger( l)) logOpt
@@ -108,6 +107,22 @@ module internal Program =
108
107
109
108
outFileOpt, directory, getItems, references, projectReferences, getProp project, project.FullFileName
110
109
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
+
111
126
let CrackProjectUsingNewBuildAPI ( fsprojFile ) =
112
127
let fsprojFullPath = try Path.GetFullPath( fsprojFile) with _ -> fsprojFile
113
128
let fsprojAbsDirectory = Path.GetDirectoryName fsprojFullPath
@@ -128,7 +143,10 @@ module internal Program =
128
143
let project = engine.LoadProject( xmlReader, FullPath= fsprojFullPath)
129
144
130
145
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 -> ()
132
150
project.SetGlobalProperty( " ShouldUnsetParentConfigurationAndPlatform" , " false" ) |> ignore
133
151
for ( prop, value) in properties do
134
152
project.SetGlobalProperty( prop, value) |> ignore
0 commit comments