#
Creating a new WebSharper project from scratch
If you don't have the WebSharper project templates installed and need a basic, server-only setup to experiment with (the equivalent of the websharper-min
project template), you can create it as follows:
Create an empty F# ASP.NET Core project
dotnet new web -lang f# -n HelloWorld
Add the
WebSharper
andWebSharper.AspNetCore
packages to it:dotnet add package WebSharper dotnet add package WebSharper.AspNetCore
Add
Site.fs
to the project with the following content:module Site open WebSharper open WebSharper.Sitelets [<Website>] let Main = Application.Text (fun ctx -> "Hello World!")
Modify
Startup.fs
as follows:... open WebSharper.AspNetCore type Startup() = member this.ConfigureServices(services: IServiceCollection) = services.AddSitelet(Site.Main) .AddAuthentication("WebSharper") .AddCookie("WebSharper", fun options -> ()) |> ignore member this.Configure(app: IApplicationBuilder, env: IWebHostEnvironment) = if env.IsDevelopment() then app.UseDeveloperExceptionPage() |> ignore app.UseAuthentication() .UseStaticFiles() .UseWebSharper() .Run(fun context -> context.Response.StatusCode <- 404 context.Response.WriteAsync("Page not found"))
Add a WebSharper configuration file for future use:
{ "$schema": "https://websharper.com/wsconfig.schema.json", "project": "site", "outputDir": "wwwroot" }
Run the app with
dotnet run
.