Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
NogginBops opened this issue Mar 21, 2022 · 5 comments
Open
Labels

Comments

@NogginBops
Copy link

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.

let findOnVSPathsThenSystemPath =
let visualStudioVersion = Environment.environVarOrNone "VisualStudioVersion"
let vsVersionPaths =
let dict = toDict knownMSBuildEntries
defaultArg (visualStudioVersion |> Option.bind dict.TryFind) getAllKnownPaths
|> List.map ((@@) Environment.ProgramFilesX86)
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
Process.tryFindFile fullList "MSBuild.exe"

@github-actions
Copy link

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

@aloisdg
Copy link

aloisdg commented Mar 21, 2022

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:

@yazeedobaid
Copy link
Collaborator

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

@yazeedobaid yazeedobaid added the bug label Apr 6, 2022
@aloisdg
Copy link

aloisdg commented Apr 6, 2022

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

@yazeedobaid
Copy link
Collaborator

@aloisdg thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants