fsprojects / ProjectScaffold

A prototypical .NET solution (file system layout and tooling), recommended for F# projects
http://fsprojects.github.io/ProjectScaffold
The Unlicense
515 stars 154 forks source link

first Build.cmd failed on windows #295

Closed susloparovdenis closed 7 years ago

susloparovdenis commented 7 years ago

I have windows10 and vs2017 with all the updates. CheckFSharpInstallation.fsproj(19,5): error : File Microsoft.FSharp.Targets not found. Is F# correctly installed on this system?

I have Microsoft.FSharp.Targets in following locations. I am confused image

full output:

Checking Paket version (downloading latest stable)...
Paket.exe 4.8.7 is up to date.
Paket version 4.8.7
1 second - ready.
Paket version 4.8.7
Resolving packages for group Build:
 - Octokit 0.24.0
 - FAKE 4.61.3
 - FSharp.Formatting 2.14.4
 - SourceLink.Fake 1.1.0
 - Microsoft.Net.Http 2.2.29
 - FSharpVSPowerTools.Core 2.3.0
 - FSharp.Compiler.Service 2.0.0.6
 - Microsoft.Bcl 1.1.10
 - Microsoft.Bcl.Build 1.0.21
Resolving packages for group Main:
 - FSharp.Core 4.0.0.1
Resolving packages for group Test:
 - NUnit 2.6.4
 - NUnit.Runners 2.6.4
C:\Users\dsusloparov\Google Drive\Workspace\tensorF\paket.lock is already up-to-date
4 seconds - ready.
Building project: CheckFSharpInstallation.fsproj
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe  CheckFSharpInstallation.fsproj /t:CheckFSharpInstallation /m      /p:RestorePackages="False" /p:OutputPath="C:\Users\dsusloparov\Google Drive\Workspace\tensorF" /p:Configuration="Release" /logger:Fake.MsBuildLogger+ErrorLogger,"C:\Users\dsusloparov\Google Drive\Workspace\tensorF\packages\build\FAKE\tools\FakeLib.dll"
Microsoft (R) Build Engine version 15.1.1012.6693
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 6/9/2017 2:07:13 PM.
     1>Project "C:\Users\dsusloparov\Google Drive\Workspace\tensorF\CheckFSharpInstallation.fsproj" on node 1 (CheckFSh
       arpInstallation target(s)).
     1>C:\Users\dsusloparov\Google Drive\Workspace\tensorF\CheckFSharpInstallation.fsproj(19,5): error : File Microsoft
       .FSharp.Targets not found. Is F# correctly installed on this system?
     1>Done Building Project "C:\Users\dsusloparov\Google Drive\Workspace\tensorF\CheckFSharpInstallation.fsproj" (Chec
       kFSharpInstallation target(s)) -- FAILED.

Build FAILED.

       "C:\Users\dsusloparov\Google Drive\Workspace\tensorF\CheckFSharpInstallation.fsproj" (CheckFSharpInstallation ta
       rget) (1) ->
       (CheckFSharpInstallation target) ->
         C:\Users\dsusloparov\Google Drive\Workspace\tensorF\CheckFSharpInstallation.fsproj(19,5): error : File Microso
       ft.FSharp.Targets not found. Is F# correctly installed on this system?

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.03
F# does not seem to be installed.
Please install F# (see http://fsharp.org/use/windows/ for instructions),
then run the build script again.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: Build script aborted: please install F# and try again.
   at <StartupCode$FSI_0005>.$FSI_0005_Init$fsx.main@()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Fake.FSIHelper.runScriptCached@315.Invoke(Unit unitVar0) in C:\code\fake\src\app\FakeLib\FSIHelper.fs:line 323
System.Exception: Build script aborted: please install F# and try again.
   at <StartupCode$FSI_0005>.$FSI_0005_Init$fsx.main@() in C:\Users\dsusloparov\Google Drive\Workspace\tensorF\init.fsx:line 36
Stopped due to error

Build failed.
Error:
Could not find file 'C:\Users\dsusloparov\Google Drive\Workspace\tensorF\build.fsx'.
pblasucci commented 7 years ago

OK. I can confirm. This seems to be happen for me (and a few others based on some Slack comments). It looks like the code for detecting the presence of F# is reporting false negatives in some case.

dsyme commented 7 years ago

@pblasucci I'll fix this now (was about to make the changes to remove SourceLink)

dsyme commented 7 years ago

@susloparovdenis @pblasucci I can't repro this. Which prompt are you running from - a VS2017 developer prompt or...

Could you try again now https://github.com/fsprojects/ProjectScaffold/pull/296 has been merged? thanks

pblasucci commented 7 years ago

@dsyme just tried again... same results. I'm using a bog standard instance of cmd.exe.

pblasucci commented 7 years ago

OK. I found a clue. It's looking in: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\VisualStudio\v\FSharp\Microsoft.FSharp.Targets

Notice the \v\ ? That should probably be \v15.0\ (or at least some number after the v). Not sure how to fix this (yet). I mean, what would cause the CheckFSharpInstallation.fsproj to have an empty value for $(VisualStudioVersion)?

dsyme commented 7 years ago

Yes, VisualStudioVersion is not set, I have no idea why. I thought it was always set.

dsyme commented 7 years ago

Can you try ToolsVersion="15.0" at the top of the project files? Just wondering.

dsyme commented 7 years ago

@pblasucci Note that using a VS2017 developer command prompt will work. But we should make it work from cmd.exe as well

pblasucci commented 7 years ago

Changing the tools version did not alter the behavior. And, just to confirm, the VS2017 developer command prompt does work. This is due to the dev prompt is putting the Visual Studio version into an environment variable (which is absent in the vanilla prompt). Also, as an aside, even though the dev prompt works correctly, it emits a (spurious) warning about F# Tools not being installed... but one issue at a time. :-)

dsyme commented 7 years ago

Do you know which MSBUILD is being run? When I use

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe

it works but when I use the very old

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe

it doesn't. I assume FAKE is in charge of choosing the right MSBuild, but I thought that FAKE 4.61.3 had an appropriate fix to always find the right version in all circumstances

pblasucci commented 7 years ago

Seems it's using

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe
dsyme commented 7 years ago

Seems it's using C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe

Does it work when you invoke that MSBUILD.EXE directly?

BTW here's a relevant FAKE issue: https://github.com/fsharp/FAKE/issues/1442. And here's the list of search paths it uses to find MSBuild.exe: https://github.com/fsharp/FAKE/blob/master/src/app/FakeLib/MSBuildHelper.fs#L25

pblasucci commented 7 years ago

No luck. Invoking MSBuild.exe directly causes the same result.

dsyme commented 7 years ago

How about if you add

  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />

to CheckFSharpInstallation.fsproj at the top of the file

dsyme commented 7 years ago

OK, adding the Microsoft.Common.Props entry fixes this for me

(I can repro this now. I was not focusing on CheckFSharpInstallation.fsproj - I was building the generated project (which has the Microsoft.Common.props entry))

pblasucci commented 7 years ago

Ding! Ding! Ding! We have a winner! Adding that sorted it.

However, I still get the following (spurious) warning:

C:\Program Files\Git\cmd\git.exe remote -v
System.Exception: Build script aborted: please install F# and try again.
   at <StartupCode$FSI_0005>.$FSI_0005_Init$fsx.main@() in C:\Projects\ProjectScaffold\init.fsx:line 36
Stopped due to error

However, everything does build and run correctly..

dsyme commented 7 years ago

Print the exception being caught here:

let checkFSharpInstallation () =
  try
    MSBuildRelease "." "CheckFSharpInstallation" ["CheckFSharpInstallation.fsproj"] |> ignore
    true
  with e ->
    false
dsyme commented 7 years ago

Make sure you're starting from clean each time, i.e.

git reset --hard master
git clean -xfd .
pblasucci commented 7 years ago

I'd been starting clean each time. But printing the caught error seems to have fixed everything. No idea why/how, though

O_o

Anyway, at least we have the fixes... now someone just needs to prepare PR.

dsyme commented 7 years ago

Done: https://github.com/fsprojects/ProjectScaffold/pull/297

dsyme commented 7 years ago

@pblasucci Could you verify? There is no printing of the caught error in that PR (did you actually get an error printed?)

pblasucci commented 7 years ago

Yup. Everything looks peachy now! 👍

There's no error being displayed now.