haf / expecto

A smooth testing lib for F#. APIs made for humans! Strong testing methodologies for everyone!
Apache License 2.0
668 stars 96 forks source link

.NET Core example fails to compile #279

Closed boechat107 closed 6 years ago

boechat107 commented 6 years ago

My settings:

I just followed the instructions on REAME and I get a build failure. I think I'm missing something very simple.

Microsoft (R) Build Engine version 15.7.179.6572 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 50 ms for /home/boechat/Codes/Fsharp/ExpectoTest/ExpectoTest.fsproj.
/home/boechat/Codes/Fsharp/ExpectoTest/Main.fs(6,5): error FS0433: A function labeled with the 'EntryPointAttribute' attribute must be the last declaration in the last file in the compilation sequence. [/home/boechat/Codes/Fsharp/ExpectoTest/ExpectoTest.fsproj]         

Build FAILED.

/home/boechat/Codes/Fsharp/ExpectoTest/Main.fs(6,5): error FS0433: A function labeled with the 'EntryPointAttribute' attribute must be the last declaration in the last file in the compilation sequence. [/home/boechat/Codes/Fsharp/ExpectoTest/ExpectoTest.fsproj]         
    0 Warning(s)
    1 Error(s)

I'm not an experienced .NET developer, but the compilation order seems correct to me in ExpectoTest.fsproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Sample.fs" />
    <Compile Include="Main.fs" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Expecto" Version="8.*" />
    <PackageReference Include="FSharp.Core" Version="4.*" />
    <PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.*" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.*" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.*" />
  </ItemGroup>
</Project>
AnthonyLloyd commented 6 years ago

Where in the README? I'm not sure what you are doing with the PackageReferences.

boechat107 commented 6 years ago

I followed the .NET Core support section and I didn't change anything in the *.fsproj file generated by the template.

0x53A commented 6 years ago

The issue is the Microsoft.NET.Test.Sdk.

It will add a new file into your build with a Main.

But you don't want this synthesized main, you want to keep your own.

So add this to a PropertyGroup:

<GenerateProgramFile>false</GenerateProgramFile>

ref https://andrewlock.net/fixing-the-error-program-has-more-than-one-entry-point-defined-for-console-apps-containing-xunit-tests/

MNie commented 6 years ago

@boechat107 I released a new version of a template with the

<GenerateProgramFile>false</GenerateProgramFile>

line in PropertyGroup. So right now everything should be ok.

boechat107 commented 6 years ago

Thanks, @0x53A and @MNie. I'll check it out on the weekend.

boechat107 commented 6 years ago

Perfect! It is working smoothly.

Thanks!