Sdk: Invalid F# template when dotnet new

Created on 11 Mar 2017  路  7Comments  路  Source: dotnet/sdk

Steps to reproduce

dotnet new console -lang F#
dotnet build

Expected behavior

Build should pass. When F# compilation items should be either not listed or there should be <EnableDefaultCompileItems>False</EnableDefaultCompileItems>. My vote is for the latter, because order of compiled files is important in F#.

Actual behavior

This is the generated fsproj

$ cat example.fsproj 
<Project Sdk="FSharp.NET.Sdk;Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Program.fs" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="FSharp.Core" Version="4.1.*" />
    <PackageReference Include="FSharp.NET.Sdk" Version="1.0.*" PrivateAssets="All" />
  </ItemGroup>

</Project>

And build failure:

ide@9e64a121ed53:/ide/work/example$ dotnet build
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.

/usr/share/dotnet/sdk/1.0.1/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.DefaultItems.targets(165,5): error : Duplicate 'Compile' items were included. The .NET SDK includes 'Compile' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultCompileItems' property to 'false' if you want to explicitly include them in your project file. For more information, see https://aka.ms/sdkimplicititems. The duplicate items were: 'Program.fs' [/ide/work/example/example.fsproj]

Build FAILED.

/usr/share/dotnet/sdk/1.0.1/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.DefaultItems.targets(165,5): error : Duplicate 'Compile' items were included. The .NET SDK includes 'Compile' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultCompileItems' property to 'false' if you want to explicitly include them in your project file. For more information, see https://aka.ms/sdkimplicititems. The duplicate items were: 'Program.fs' [/ide/work/example/example.fsproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.60

Environment data

$ dotnet --info
.NET Command Line Tools (1.0.1)

Product Information:
 Version:            1.0.1
 Commit SHA-1 hash:  005db40cd1

Runtime Environment:
 OS Name:     debian
 OS Version:  8
 OS Platform: Linux
 RID:         debian.8-x64
 Base Path:   /usr/share/dotnet/sdk/1.0.1

Most helpful comment

@tomzo @petertiedemann you miss the dotnet restore step.

dotnet new console -lang f#
dotnet restore
dotnet build
dotnet run

for more info about f# see wiki https://github.com/dotnet/netcorecli-fsc/wiki/.NET-Core-SDK-1.0.1

@tomzo as a note, EnableDefaultCompileItems is added already by FSharp.NET.Sdk But because there was not dotnet resto, it was not added

if you get more issues, please fill in https://github.com/dotnet/netcorecli-fsc/issues

@piotrpMSFT this can be closed.

All 7 comments

Getting exactly the same error.

With just VS2017 installed:

.NET Command Line Tools (1.0.0)

Product Information:
 Version:            1.0.0
 Commit SHA-1 hash:  e53429feb4

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\1.0.0

Installing the SDK (to get the newer version):

.NET Command Line Tools (1.0.1)

Product Information:
 Version:            1.0.1
 Commit SHA-1 hash:  005db40cd1

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\1.0.1

@tomzo @petertiedemann you miss the dotnet restore step.

dotnet new console -lang f#
dotnet restore
dotnet build
dotnet run

for more info about f# see wiki https://github.com/dotnet/netcorecli-fsc/wiki/.NET-Core-SDK-1.0.1

@tomzo as a note, EnableDefaultCompileItems is added already by FSharp.NET.Sdk But because there was not dotnet resto, it was not added

if you get more issues, please fill in https://github.com/dotnet/netcorecli-fsc/issues

@piotrpMSFT this can be closed.

Enrico thanks for that. I've been trying to fix this issue for the past two hours.!

@Fedreg the new sdk 1.0 released some days ago now will show two warnings (if fsharp.net.sdk is not added/restored as package ref) and an error if restore is not done (the obj/project.assets.json doesnt exists), with a more clear message about "you forgot restore"

Good to know! Will make it more beginner friendly. Thanks for the update!

@enricosada, what version of the SDK is it that has this fix? I'm running .NET Command Line Tools (2.0.0-preview1-005977) but I still have the unfortunate experience described in the original issue. From what I can see here this the latest version available but I don't see how the name (sdk 1.0) is associated with this SDK.

@jpierson 2.0.0-preview1 doesnt work with F#, see https://github.com/dotnet/netcorecli-fsc/wiki/.NET-Core-SDK-2.0.0-preview1 for more info.

You need to use 1.0 (https://github.com/dotnet/netcorecli-fsc/wiki/.NET-Core-SDK-1.0) for a stable and working version

Or latest dev 2.0.0-preview2 (https://github.com/dotnet/netcorecli-fsc/wiki/.NET-Core-SDK-2.0.0-preview2) if you really want to use 2.0.0 (but see wiki, there are some notes)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

moozzyk picture moozzyk  路  3Comments

joffreykern picture joffreykern  路  3Comments

krwq picture krwq  路  3Comments

aguacongas picture aguacongas  路  3Comments

noelitoa picture noelitoa  路  3Comments