FAKE icon indicating copy to clipboard operation
FAKE copied to clipboard

Wrong version of MSBuild found if only Visual Studio 2022 is installed

Open NogginBops opened this issue 3 years ago • 5 comments

This code only looks in the Program Files (x86) folder for Visual Studio installations, but vs2022 installs in Program Files, so MSBuild provided with vs2022 will not be picked up by Fake.DotNet.MSBuild.

https://github.com/fsprojects/FAKE/blob/e313c3b25a2c3d683d0ceed735a1a2b9b15a4fb4/src/app/Fake.DotNet.MSBuild/MSBuild.fs#L236-L249

NogginBops avatar Mar 21 '22 12:03 NogginBops

Welcome to the FAKE community! Thank you so much for creating your first issue and therefore improving the project!

github-actions[bot] avatar Mar 21 '22 12:03 github-actions[bot]

Nice catch. Maybe we should hardcoded the program file into each paths or we can write a small logic:

pseudo code

// wont work because visualStudioVersion can be none
let getProgramFilesPath visualStudioVersion = 
    if (float visualStudioVersion) < 17.0
	then Environment.ProgramFilesX86
	else Environment.ProgramFiles

let findOnVSPathsThenSystemPath =
                let visualStudioVersion = Environment.environVarOrNone "VisualStudioVersion"
Environment.ProgramFiles
                let vsVersionPaths =
                    let dict = toDict knownMSBuildEntries
                    defaultArg (visualStudioVersion |> Option.bind dict.TryFind) getAllKnownPaths
                    |> List.map (fun path -> (getProgramFilesPath visualStudioVersion) @@ path)
                let vsWhereVersionPaths =
                    let orderedVersions = MSBuildExeFromVsWhere.getOrdered()
                    let all = orderedVersions |> List.collect (fun e -> e.Paths)
                    let dict = toDict orderedVersions
                    defaultArg (visualStudioVersion |> Option.bind dict.TryFind) all
                let fullList = vsWhereVersionPaths @ vsVersionPaths |> List.distinct

source:

  • https://docs.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=net-6.0
  • https://docs.microsoft.com/en-us/visualstudio/install/change-installation-locations?view=vs-2022

aloisdg avatar Mar 21 '22 16:03 aloisdg

Thanks for reporting! Would anyone like to send a PR for this issue?

yazeedobaid avatar Apr 06 '22 12:04 yazeedobaid

@yazeedobaid I am willing to transform my pseudo code into something useful.

aloisdg avatar Apr 06 '22 12:04 aloisdg

@aloisdg thanks

yazeedobaid avatar Apr 06 '22 12:04 yazeedobaid