15

I'm having trouble creating F# Console App using .Net Framework (not .Net Core). When I open:

Visual Studio 2017 -> New project -> Visual F# -> .Net Standard

the only template visible is Class Library.

Using Visual Studio Installer I added following packages:

  • F# Language Support (I know this is a dependency for .Net Core, but it still might be important)
  • F# Desktop Language Support (the installer said it has only 147KB size, is that okay?)

However, this didn't change anything - still there is no template for Console Application. I have also tried to see if target version of .NET Framework changes anything, but it doesn't - am I missing anything else?

Note: I can't use the .Net Core version, even though I would like to, because the use of the framework I'm going to use only supports .Net Standard framework - it requires System.Windows.Forms.

1

4 Answers 4

21

Apparently I'm blind. However, to my excuse, I need to clarify:


To create a Console App using .Net Framework (not Core) I needed to click on:

Visual Studio 2017 -> New project -> Visual F# (the template is here)

and not:

Visual Studio 2017 -> New project -> Visual F# -> .Net Standard (the template is one step up in hierarchy)


Explanation:

As stated by @PanagiotisKanavos in comments:

.NET Standard is only used for portable libraries.

So it's not even supposed to be there at all.


NOTE:
F# Desktop Language Support is a required package containing the templates for F# Console App (and other non-core templates).

If you do not have this installed, you will not see the template no matter where you click. You can install it using Visual Studio Installer through Individual Components tab.

9
  • 2
    .NET Standard is only used for portable libraries Jan 26, 2018 at 10:29
  • A lesson I learned the hard way. Thanks for clarification though.
    – Asunez
    Jan 26, 2018 at 10:32
  • People have been discussing .NET Core and .NET Standard for a couple of years now, with a lot of articles explaining how Standard, Framework and Core relate to each other Jan 26, 2018 at 10:33
  • @PanagiotisKanavos Indeed, but what was misleading for me was that I had the choice between Core or Standard, with Framework not to be found. I just accidentally clicked on the parent node to find what I was looking for. It wasn't intuitive for sure.
    – Asunez
    Jan 26, 2018 at 10:34
  • 6
    @NikolaiKoudelia When you open Visual Studio Installer and switch to Individual Components do you have F# Language Support and F# Desktop Support ticked? If not, install them. Also - see if you switch .Net version (upper part of the window) if this helps.
    – Asunez
    Feb 7, 2018 at 14:44
1

This is not an answer but a work around.

You can create 2 projects. F# library and a C# console application. Reference the F# project to your C# console application. From there you can call your F# methods from inside of your console app.

2
  • That's good to know, and when I give up searching for answer I will try this approach. To add up to workaround solutions, I think it is also possible to add System.Windows.Forms dll to .Net Core projects, but I suppose the stability of this is rather scarce. Have an upvote though for a possible workaround :)
    – Asunez
    Jan 26, 2018 at 9:34
  • 3
    There's no need to create a C# console application, F# console apps work just fine. .NET Standard though is only used for portable libraries, no matter the language Jan 26, 2018 at 10:32
0

Visual Studio 2019:

  1. Open Visual Studio Installer.
  2. Go to the "Individual components" tab
  3. Filter by F#
  4. Install all

Pro tip: to select templates like on the selected answer to this question, you can install:

How to restore normal "New Project" windows on Visual Studio 2019

0

The process is the same for F#, just filter by F# under the add individual components tab. Background -- This is a changed/broken issue that Microsoft changed deliberately you can read more here and the issue reported here but you can fix this with the 2 options listed below, i.e. A) enable it OR B) add it to VS via the repair tool


  • Option 1: you may have to enable this option...

Tools > Options > Preview Features > “Show all .NET Core templates in the New project dialog (requires restart)”.

Enable the option


  • Option 2: Install via Visual Studio Installer like so..

You can install missing workloads using the repair VS (this will also update the installer) and make sure you check the optional packages you want from the VS Installer tool please see this

repair the VS install


The process is the same for F#, just filter by F# under the add individual components tab its the 2nd tab in the picture below.

After the installer starts check if the .NET Core workload is selected for desktop and console.. like below.. on the right pane you will need to check the correct boxes

Select the core tools & Filter for F# tools by visual studio components

Now, if you have already followed the above steps, then verifying you selected the checkbox of ".net-Desktop development" on top right is selected or not on Visual Studio installer: delete the cache and restore

i.e. you could restore the template in VS2017/2019 then try it again.

Please refer to the following steps:

  1. DELETE the ItemTemplatesCache, ProjectTemplatesCache folder ent. prof. etc.. C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE.
  2. In the command prompt, navigate to the location of devenv.exe. This file is located in \Common7\IDE.
  3. Type/Run this command devenv /installvstemplates and press Enter.

.Net Desktop Dev Workload

FYI - your templates cache is here, containing folders named after the zip files from your archives in the template folder. you will need admin priviledge for edits/delete.

%AppData%\Microsoft\VisualStudio\{some_version}\ItemTemplatesCache\


Option 3: debugging your env. Template Config folder

Checking/Diagnosing the version:

run this dotnet --version install the correct core version https://dotnet.microsoft.com/download/dotnet/5.0 more here this dotnet new -u will tell you which templates are installed, you can uninstall, clear the packages cache, restart and reinstall with the repair tool.

Download and run collect.exe - https://aka.ms/vscollect - and share the log file created in %TEMP%\vslogs.zip with MS on github

FYI - This is what your template folder structure in visual studio should look like.

└───mytemplate
    │   console.cs
    │   readme.txt
    │
    └───.template.config
            template.json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.