question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Web (EmptyWeb) F# version

See original GitHub issue

Should F# version of web project (Web/Empty) be added? We provide one with generator-aspnet and I’m rewriting it for RC: https://github.com/OmniSharp/generator-aspnet/tree/master/templates/projects/fsharp_emptyweb https://github.com/OmniSharp/generator-aspnet/issues/881 Maybe not now, but do you want a PR?

Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:18 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
seancpeterscommented, Feb 4, 2017

It’s probably easiest if I discuss here what needs to be done.

Let’s use the C# empty web template as an example: https://github.com/dotnet/templating/tree/master/template_feed/Microsoft.DotNet.Web.ProjectTemplates/content/EmptyWeb-CSharp

For an F# empty web template, you’ll want to make a directory /EmptyWeb-FSharp/ at the same level as the /EmptyWeb-CSharp/ directory. Everything for the F# template will go under /EmptyWeb-FSharp/ It’s probably easiest to name the files similar to how they’re named in the C# template - you’ll want:

  • Company.WebApplication1.fsproj
  • Program.fs
  • Startup.fs

We also need to look at the template.json file for the C# emptyweb project: https://github.com/dotnet/templating/blob/master/template_feed/Microsoft.DotNet.Web.ProjectTemplates/content/EmptyWeb-CSharp/.template.config/template.json

You’ll need to make a /EmptyWeb-FSharp/.template.config/template.json file for the F# emptyweb project. You can copy the C# one, and just make a few changes. Here’s the start of the file, it’s the only place changes will need to be made:


{
  "author": "Microsoft",
  "classifications": ["Web", "Empty"],
  "name": "Empty ASP.NET Core Web Application",
  "groupIdentity": "Microsoft.Web.Empty",
  "identity": "Microsoft.Web.Empty.CSharp",
  "shortName": "web",
  "tags": {
    "language": "C#",
    "type": "project"
  },
  "sourceName": "Company.WebApplication1",
  "preferNameDirectory": true,
  "symbols": {
    "IncludeApplicationInsights": {
      "type": "parameter",
      "datatype": "bool",
      "defaultValue": "false",
      "description": "Whether or not to include Application Insights in the project"
    },
    "Framework": {
      "type": "parameter",
      "datatype": "choice",
      "choices": [
        {
          "choice": "netcoreapp1.0",
          "description": "Target netcoreapp1.0"
        },
        {
          "choice": "netcoreapp1.1",
          "description": "Target netcoreapp1.1"
        }
      ],
      "defaultValue": "netcoreapp1.0"
    },

I don’t think your F# template has Application Insights built in, so we can remove the IncludeApplicationInsights section under the “symbols”. You’ll want to change “language”: “C#” … to be “language”: “F#” And change the “identity”: “Microsoft.Web.Empty.CSharp” … to be “identity”: “Microsoft.Web.Empty.FSharp”, No other changes should be necessary in the template.json file (copy)

This part doens’t need to be changed. But it is important for the changes we’ll need to make in the .fs files: “sourceName”: “Company.WebApplication1”, When you create a template, the engine determines a string value for “sourceName”.

Sidenote: How the sourceName is determined with the command “dotnet new”: - if you provide "-n Name"option, then sourceName = Name - if you do not provide “-n Name”, but provide a “-o DirectoryName” option, then the sourceName = DirectoryName - if you specify both “-o DirectoryName” and “-n Name”, then sourceName = Name - if you don’t specify either option, then sourceName = the name of the current directory

That value will replace the string literal “Company.WebApplication1” in all the filenames, and in all the file content in the template. For example, if I create a template with: dotnet new web -n MyWebProject all instances of “Company.WebApplication1” will be replaced with “MyWebProject”.

Since we are naming the proj file “Company.WebApplication1.fsproj” in the template, the output file name will become “MyWebProject.fsproj”

The same idea should be used for the namespace value in the .fs files. In the Program.fs & Startup.fs files, you have the line: open <%= namespace %>

For the dotnet template, this will become: open Company.WebApplication1

… and when the template is generated, the output .fs files will contain the line: open MyWebProject

The .fsproj file contains this line: <TargetFramework><%= dotnet.targetFramework %></TargetFramework> For dotnet templates, we do this differently. Under the “symbols” section of the template.json file, there is a “Framework” section. Since it has “type”: “parameter”, it’s something the user can specify. We use the specified value to format the TargetFramework. You can copy exactly what is in the existing C# template, specifically:

  <PropertyGroup>
    <TargetFramework Condition="'$(Framework)' != 'netcoreapp1.1'">netcoreapp1.0</TargetFramework>
    <TargetFramework Condition="'$(Framework)' == 'netcoreapp1.1'">netcoreapp1.1</TargetFramework>

The template engine evaluates the Condition statements, the ones that are true are written to the target, others are not.

There is one more extra file to add to your template. It should be: /EmptyWeb-FSharp/.template.config/dotnetcli.host.json and can contain exactly this:

{
  "symbolInfo": {
    "Framework": {
      "longName": "framework"
    }
  }
}

Everything else in the template is general-purpose. This file will only be used by the command line “dotnet new”. It’s just saying that for the parameter “Framework”, we want the parameter to be specified with “framework” instead.

I think I covered everything your template already does. If I missed anything, or if anything is unclear, please let me know.

0reactions
mlorbetskecommented, Apr 19, 2017

Yep, it needs the nightly of the 2.0 cli unfortunately. I believe that’s the total set of differences, @glennc can probably point out any changes that are coming.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core RC2 Empty Web template final version #704
Just tested this and got it working. Quick question. Why does the Empty template include "extra" namespaces in files like Program.cs and Startup.cs?...
Read more >
ASP.NET Empty Web Applcation for F# - Stack Overflow
Does anyone know if there are web templates for F#? Specifically, the ASP.NET Empty Web Application. I am looking for VS2012. asp.net ·...
Read more >
dotnet new <TEMPLATE> - .NET CLI
The dotnet new command creates new .NET projects based on the specified template.
Read more >
How install and use Yeoman to generate a ASP.NET Core ...
Step 2: Run the ASP.NET generator for yo · Empty Web Application · Empty Web Application (F#) · Console Application · Console Application...
Read more >
HTTPS in ASP.NET Core from Scratch - The Blinking Caret
Select Empty Web Application. A simple web project will be created that just has page with the text “Hello World”. If you are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found