Skip to content
David Stephens edited this page Mar 7, 2016 · 7 revisions

Contents

  1. Install the .NET CLI
  2. “Hello World!”
  3. Restore Dependencies
  4. Run it!
## Install the .NET CLI

Install the .NET CLI from http://dotnet.github.io/getting-started/. This will install the latest version (nightly).

NOTE Before you install, check if the latest binaries work with F#. Otherwise, download the last-known-good version.

After you install the tools, check if the .NET CLI works, by running:

dotnet --version

The expected output (and exit code zero) is:

.NET Command Line Tools (1.0.0-beta-001494)

Product Information:
 Version:     1.0.0-beta-001494
 Commit Sha:  c7a9d1d63a

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.1.7601
 OS Platform: Windows
 Runtime Id:  win7-x64
## Hello World!

The simplest way to create a new F# console app for .NET Core is to use the dotnet new command.

NOTE The mkdir and cd are needed because dotnet new creates the project in the current directory.

mkdir helloworld
cd helloworld
dotnet new --lang f#

If everything is okay, you should see:

Created new F# project in c:\helloworld.

The dotnet new --lang f# command creates the following in the current directory:

  • Program.fs the F# source file with main
  • project.json the project file
  • NuGet.Config list of Nuget feeds.
## Restore Dependencies

The project depends on the .NET Standard Library and FSharp.Core library. Before you can run the app, you need to restore all of the project's dependencies.

To download these dependencies, run:

dotnet restore

The expected output is:

log  : Restoring packages for c:\helloworld\project.json...
info :   GET https://dotnet.myget.org/F/dotnet-core/api/v3/flatcontainer/microsoft.netcore.platforms/index.json
info :   GET https://api.nuget.org/v3-flatcontainer/microsoft.netcore.platforms/index.json
info :   OK https://dotnet.myget.org/F/dotnet-core/api/v3/flatcontainer/microsoft.netcore.platforms/index.json 561ms
info :   GET https://www.myget.org/F/fsharp-daily/api/v3/flatcontainer/microsoft.netcore.platforms/index.json
info :   OK https://api.nuget.org/v3-flatcontainer/microsoft.netcore.platforms/index.json 517ms
info :   NotFound https://www.myget.org/F/fsharp-daily/api/v3/flatcontainer/microsoft.netcore.platforms/index.json 108ms
info : Committing restore...
log  : Restore completed in 34962ms.
NuGet Config files used:
    c:\helloworld\NuGet.Config
    C:\Users\user\AppData\Roaming\NuGet\NuGet.Config
Feeds used:
    https://dotnet.myget.org/F/dotnet-core/api/v3/index.json
    https://api.nuget.org/v3/index.json
    https://www.myget.org/F/fsharp-daily/api/v3/index.json

This command will create in the project directory:

  • project.lock.json

The project.lock.json contains the list of all packages/version needed by the project

## Run it!

To build and run the console app, use the dotnet run command. The dotnet run command builds the project, and if successful, runs it with the command line arguments passed to dotnet run.

dotnet run arg1 arg2

If everything it's okay, the output should be:

Compiling helloworld for DNXCore,Version=v5.0

Compilation succeeded.
    0 Warning(s)
    0 Error(s)

Time elapsed 00:00:05.3219069


Hello World!
[|"arg1"; "arg2"|]

The first part is the build output. The second part the console app execution output.

NOTE On OS X and Linux, there is a known issue which will cause an error (Access to the path '/usr/local/share/dotnet/bin' is denied.) and cause dotnet run to fail. See the Status page for a workaround on OS X.

Clone this wiki locally