Bug 39575 - F# stock console app doesn't compile
Summary: F# stock console app doesn't compile
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: F# Add-in ()
Version: 6.0.0 (C7)
Hardware: PC Windows
: Normal normal
Target Milestone: master
Assignee: Jason Imison
Depends on:
Reported: 2016-03-14 04:17 UTC by Andres G. Aragoneses
Modified: 2016-04-13 04:06 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

screenshot of the problem (50.98 KB, image/png)
2016-03-14 04:17 UTC, Andres G. Aragoneses
Sample project (7.33 KB, application/x-zip-compressed)
2016-03-30 16:52 UTC, Jason Imison

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 39575 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Andres G. Aragoneses 2016-03-14 04:17:34 UTC
Created attachment 15392 [details]
screenshot of the problem

Just testing XS 6.0 build 4761.

If I create a new F# project, it doesn't build.

See screenshot (which shows the build error and a tooltip about an red underline error in the editor).
Comment 1 Andres G. Aragoneses 2016-03-24 03:29:31 UTC
So the 2 errors in the screenshot are:

a) The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\FSharp\Microsoft.FSharp.Targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. (MSB4019)

b) Error: Unable to read assembly 'C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\3.0\Runtime\v2.0\FSharp.Core.dll'

WRT (b), not sure why it happens, because that file exists in my system. Although when I create F# projects in VS2012 they reference this other one:

C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\3.0\Runtime\v4.0\FSharp.Core.dll

WRT (a), F# projs created by my VS do it this way:

<Import Project="$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')" />
Comment 2 Jason Imison 2016-03-30 14:56:47 UTC
VS2015 creates the targets like this :-

    <MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
    <When Condition="'$(VisualStudioVersion)' == '11.0'">
      <PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')">
        <FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
      <PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets')">
  <Import Project="$(FSharpTargetsPath)" />

If this works in XS on mono, I'll use this.
Comment 3 Andres G. Aragoneses 2016-03-30 15:38:16 UTC
> VS2015 creates the targets like this

Can you attach a .csproj file so I can test it with my VS2012 and XS for Windows?
Comment 4 Jason Imison 2016-03-30 16:52:04 UTC
Created attachment 15558 [details]
Sample project

Sure, here you go, I've zipped up File -> New FSharp Console Application from VS 2015
Comment 5 Andres G. Aragoneses 2016-03-31 03:55:02 UTC
Ok thanks. So FYI:

> Sample project

If I open this project in VS2012, first it tells me the .NET framework is too high for my version, and offers me to change it back to 4.5 (instead of 4.5.2). After that, it opens it fine, and when compiling it gives a warning, not an error, which is:

Warning	1	Could not resolve this reference. Could not locate the assembly "FSharp.Core, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.	C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets	1605	5	ConsoleApplication2

The app runs perfectly after being compiled.

In XS6 4761 the story is different: if I compile the solution I get this error:

C:\Users\Andres\Downloads\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.fsproj(3,3): Error MSB4102: The value "" of the "Project" attribute in element <Import> is invalid. Parameter "path" cannot have zero length. (MSB4102) (ConsoleApplication2)
Comment 6 Andres G. Aragoneses 2016-04-07 04:03:44 UTC
I guess this is what XS should write in F# projects (confirmed by 2 votes already ;) ):

Comment 7 Jason Imison 2016-04-07 07:11:17 UTC
That won't work for future versions though.
Comment 8 Andres G. Aragoneses 2016-04-13 04:06:50 UTC
> That won't work for future versions though.

Why not?

BTW, I've updated my answer to use <Choose> tags instead, to avoid importing more than one Targets file at the same time:

    <When Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets')">
      <FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
        <When Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.1\Framework\v4.0\Microsoft.FSharp.Targets')">
            <FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.1\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
            <When Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')">
                <FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
  <Import Condition="'$(FSharpTargetsPath)' != ''" Project="$(FSharpTargetsPath)" />

I tested inserting this block (and removing your Choose block) in the project you attached, and it worked for me! With XS 6.0.4968 for Windows.