Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.
Enrico Sada edited this page Jan 31, 2017 · 13 revisions

Some answers to frequently asked questions about developing for .NET Core. Some answers apply only to F#, others to all languages.

If something works with C#, it should work exactly the same for F#.

TABLE OF CONTENTS

  • This is a FAQ, where are the real docs?
  • .NET Core works with F#? Now? Without going crazy?
    • Where to report bugs?
  • Preview? RC?
  • How can i install it?
  • I maintain an F# library published as nupkg and i want to support .NET Core
    • Ok i want to start to convert a project?
    • a new target framework?
    • what dependencies version of libraries/tools?
    • how can i check version resolved?
    • some code need to be changed for .net core.. two version!
    • Can i create a single nuget package with multiple framework versions inside (.NET 4.6, .NET Core)?
      • But i already create the nuget package in my build, i dont want to use project.json for every framework
        • i need to merge nupkg manually?
  • Tools support?
  • Travis/Appveyor
  • Want to help?

This is a FAQ, where are the real docs?

The docs are really nice to read, and explain all scenarios.

So they are a good first read.

They're also open source, send a PR 😄

.NET Core works with F#? Now? Without going crazy?

Yes, even during the beta, it was already OK with workarounds

With preview2, .NET Core and F# work OOTB. For example, see a suave sample app, working cross platform (win/ubuntu/osx/docker). Or use rc3 for msbuild based.

Where to report bugs?

It's not RTM yet, if you see a bug, open an issue in:

Is .NET Core in Preview? RC? RTM?

When .NET Core was in beta, the tooling (dotnet/cli, project.json, xproj) and the .NET Core (coreclr, corefx, bcl) was bundled together using same version (beta and after rc2).

The dotnet team split the two parts, the .NET Core (more ready for production, RC quality => RC2) from tooling (renamed from .NET CLI to .NET Core SDKin preview1)

So:

  • .NET Core (now RTM) => Run apps with .NET Core runtime, clr and base class libraries, (dotnet/coreclr, dotnet/corefx)
  • .NET Core SDK (now preview2) => tooling. Develop apps with .NET Core and the SDK+CLI (Software Development Kit/Command Line Interface) tools, like dotnet/cli (the tool that runs dotnet build)

How can i install it?

See the docs

  1. From http://dot.net choose .NET Core.
  2. That page shows the quickstart. For F#, just add --lang f# to dotnet new.

Or follow the (a bit hidden) Other downloads link for other os and types.

Both .NET Core and .NET SDK has two versions:

  • from os native installers: like msi/pkg, install globally in the machine (see options)
  • from binaries: just a zip, download => unzip => add to PATH => dotnet ready (multiple version can be installed in different directories). Zero fear about breaking the machine configuration. ❤️

I maintain an F# library published as nupkg and I want to support .NET Core

Ok, How do I start converting a project?

There is not an updated tutorial yet (this one works for beta, but procedure is the same)

The typical procedure is

  1. Go to same directory of your .fsproj
  2. Copy a project.json of a lib
  3. Restore all dependencies ( dotnet restore )
  4. Add all source files, same list as Compile inside .fsproj
  5. Add all additional nuget packages dependencies, like in .fsproj
  6. Add all compiler directive in buildOptions.defines of project.json
  7. Run dotnet build and fix any errors
  8. Run dotnet pack to create your package

Check some alredy converted projects, like https://github.com/SuaveIO/suave

A new target framework?

See docs, it's explained better

Usually, simplified (again read the docs)

Type Name TFM Latest version as preview2
library .NET Standard netstandard netstandard1.6
console app .NET Core Application netcoreapp netcoreapp1.0

TFM means target framework moniker, the short name ( ref nugets targetframeworks docs )

So, simplified:

  • a library should target netstandard1.6
  • a console app should target netcoreapp1.0

What are the required dependencies (and their versions) for F# libraries/tools?

Is ok to use files generated by dotnet new --lang f#

A F# library should depend (inside dependencies) on:

  • Microsoft.FSharp.Core.netcore: contains the FSharp.Core assembly, no GAC in .NET Core, only nuget packages
  • NETStandard.Library metapackage: read the docs, version depends on features
  • additional packages as needed, but not Microsoft.NETCore.App metapackage

A F# console app should depend (inside dependencies) on:

  • Microsoft.FSharp.Core.netcore: contains the FSharp.Core assembly
  • Microsoft.NETCore.App metapackage: read the docs, version is 1.0.0 for preview2

How can I check which version of a dependency was resolved?

do dotnet restore and open project.lock.json, search for package name.

I need to change some of my code to run on .net core ... What do I do?

If some code need to be changed, it's possible to maintain two versions of the same code under '#if` defines. When building, an upper case compiler define of TFM is passed to compiler.

so if

    "frameworks": {
        "netstandard1.6": { 

a compiler directive NETSTANDARD1_6 (the . becomes _) is passed to compiler

NOTE the compiler is F# 4.0, so it's possibile to use #if !DEF, #if A || B and #if A && B

like

#if NETSTANDARD1_6
   let a = typeof<Program>.GetTypeInfo().Assembly.Name
#else
   let a = typeof<Program>.GetType().Assembly.Name
#endif

Can I create a single nuget package with multiple framework versions inside (.NET 4.6, .NET Core)?

Yes, nuget packages support multiple versions, and the .NET Core framework is like another target framework (like PCL, or .NET 3.5).

Just add the dependency group in your nuspec file and the assemblies under lib

But I already created the nuget package in my build, I don't want to use project.json for every framework

No need to go all in with project.json (it said it is not feeling well lately...)

You can use the .NET SDK cli tools (like dotnet pack or dotnet build) to build the assemblies (or the package) and add these to your package

Do I need to merge nupkg manually?

nuget pack expects a nuspec and directory, so this works already.

Or you can use a opensource third party tool (https://github.com/enricosada/dotnet-mergenupkg) to merge the already built packages.

NOTE BY AUTHOR the dotnet-mergenupkg is an option written by me (@enricosada), so I like it and use it for some F# open source projects (suave/FCS/chessie). It tries to not change current build workflow, but uses dotnet cli to max. Feel free to ignore it.

  1. Build your package A normally
  2. Create a package B with .NET Core (netstandard1.6) using dotnet pack
  3. Use dotnet mergenupkg to merge only assembly/nuspec for netstandard1.6 from B to A, so A contains both.

Tools support?

  • Visual Studio: adding an xproj file, the Build/Run works, but not debug/intellisense
  • Visual Studio Code: Yes build/run/intellisense, with the Ionide plugin for F#. After the first build (dotnet build), it should just work. No debugging.
  • Notepad: from day 0

Travis/Appveyor

Both support .NET Core Sdk, but some changes are required in the config file to have the sdk already installed ootb (faster than download+install). See [https://docs.microsoft.com/en-us/dotnet/articles/core/tools/using-ci-with-cli] for more info

Want to help?

Awesome! See F# Core engineering group about .NET Core and SDK