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

MSBuild doesn't support MSBuild 16 / VS 2019. #2271

Closed
csmager opened this issue Mar 8, 2019 · 7 comments · Fixed by #2274
Closed

MSBuild doesn't support MSBuild 16 / VS 2019. #2271

csmager opened this issue Mar 8, 2019 · 7 comments · Fixed by #2274

Comments

@csmager
Copy link
Contributor

csmager commented Mar 8, 2019

Description

MSBuild doesn't support MSBuild 16 / VS 2019.

Repro steps

e.g. MSBuild.runRelease.

Expected behavior

It should pick the latest installed version

Actual behavior

I have uninstalled VS 2017, what gets executed is MSBuild 14.

Known workarounds

Run with MSBuild environment variable, e.g.

fake run -e "MSBuild=C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe"

Related information

  • Operating system Windows
@matthid
Copy link
Member

matthid commented Mar 8, 2019

As we now use BlackFox.VSWhere I'd assumed this would "just work":

https://github.com/fsharp/FAKE/blob/00d5bb2d3644c80314630591d66ed302d1b45032/src/app/Fake.DotNet.MSBuild/MSBuild.fs#L91-L120

/cc @vbfox

@csmager
Copy link
Contributor Author

csmager commented Mar 8, 2019

I ran that in FSI, I get this result (I've now got VS 2017 installed):

map [
    (15.0, [C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\15.0\Bin
            C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin])]

There's no MSBuild.exe at that location in VS 2019 (the folder exists, it has a Roslyn folder with two dlls in). MSBuild.exe is in MSBuild\Current\Bin, which is v16.0.

I suspect the regex needs modifying & maybe we should check if MSBuild.exe exists? Or is that implicitly happening later anyway? However, then we don't know the version, given all we have is 'Current'.

@vbfox
Copy link
Contributor

vbfox commented Mar 8, 2019

I'm at work and can't easily PR today but something like that should work and keep compat:

module MSBuildExeFromVsWhere = 
    open BlackFox.VsWhere 
    open System.Text.RegularExpressions 
 
    let private getAllVsPath () = 
        VsInstances.getWithPackage "Microsoft.Component.MSBuild" true 
        |> List.map (fun vs -> vs.InstallationPath) 
 
    let private getAllMsBuildPaths vsPath =
        let versionsDir = Path.Combine(vsPath, "MSBuild") 
        if Directory.Exists(versionsDir) then 
            Directory.EnumerateDirectories(versionsDir) 
            |> Seq.map (fun d -> Path.Combine(d, "Bin", "MSBuild.exe"))
            |> Seq.choose(fun exe ->
               try
                   let v = FileVersionInfo.GetVersionInfo(exe)
                   Some (sprintf "%d.0" v.FileMajorPart, Path.GetDirectoryName(exe))
               with
               | _ -> None)
            |> List.ofSeq 
        else 
            [] 
 
    let private all = lazy( 
        getAllVsPath () 
        |> List.collect getAllMsBuildPaths 
        |> List.groupBy fst 
        |> List.map (fun (v, dirs) -> v, dirs |> List.map snd) 
        |> Map.ofList) 
 
    let get () = all.Value  

@csmager
Copy link
Contributor Author

csmager commented Mar 8, 2019

Looks good to me

 map [
    (15.0, [C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin]); 
    (16.0, [C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin])]

@matthid
Copy link
Member

matthid commented Mar 12, 2019

@csmager can you send a PR?

@csmager
Copy link
Contributor Author

csmager commented Mar 12, 2019

Will do this week!

@gremlm
Copy link

gremlm commented Aug 9, 2019

For calculating code metrics I have included Microsoft.CodeAnalysis.Metrics 2.9.4 nuget package to my csproj project.
Before executing msbuild from the command line, I have called "nuget.exe restore", and it correctly found MSBuild and restore package:
"MSBuild auto-detection: using msbuild version '16.200.19.32702' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\bin'.
Restoring NuGet package Microsoft.CodeAnalysis.Metrics.2.9.4. ..."

Then, from command line I am calling msbuild with /t:Metrics option:
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\bin\MSBuild.exe" /p:Configuration=Debug /t:Metrics My.sln "

which ended with following error:
"Unhandled Exception: System.ArgumentException: Directory "C:\Program Files (x86)\Microsoft Visual Studio\2019\TestAgent\MSBuild\Current\Bin" does not exist
Parameter name: msbuildPath
at Microsoft.Build.Locator.MSBuildLocator.RegisterMSBuildPath(String msbuildPath)
at Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults()
at Metrics.Program.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)"

It looks like Metrics.exe looking for msbuild in wrong location, but nuget.exe in correct one.
Why msbuildPath is set to the wrong location?

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

Successfully merging a pull request may close this issue.

4 participants