F#: How to avoid "[FS0988] Main module of program is empty: nothing will happen when it is run" in Tests Project?

Viewed 886

I have a .NET solution with the projects below:

  • Console: Console .NET Core 2.2
  • Domain: .NET Standard 2.0
  • Domain.Tests: Console .NET Core 2.2 (XUnit)
  • Infrastructure: .NET Standard 2.0

My Domain.Tests.fsproj is defined as:

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

    <PropertyGroup>

        <IsPackable>false</IsPackable>
        <GenerateProgramFile>false</GenerateProgramFile>
        <TargetFramework>netcoreapp2.2</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="FsCheck" Version="3.0.0-alpha4" />
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
        <PackageReference Include="xunit" Version="2.4.0" />
        <PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
    </ItemGroup>

    <ItemGroup>
      <Compile Include="Dsl.fs" />
      <Compile Include="OpenAccountTests.fs" />
      <Compile Include="CloseAccountTests.fs" />
      <Compile Include="DepositCashTests.fs" />
      <Compile Include="WithdrawCashTests.fs" />
      <Compile Include="WireMoneyTests.fs" />
      <Compile Include="RequestAddressChangeTests.fs" />
      <Compile Include="RequestEmailChangeTests.fs" />
      <Compile Include="RequestPhoneNumberChangeTests.fs" />
      <Compile Include="ValidateAddressChangeTests.fs" />
      <Compile Include="ValidateEmailChangeTests.fs" />
      <Compile Include="ValidatePhoneNumberChangeTests.fs" />
    </ItemGroup>

    <ItemGroup>
      <ProjectReference Include="..\Domain\Domain.fsproj" />
    </ItemGroup>

</Project>

But when compiling the solution I have the following warning:

ValidatePhoneNumberChangeTests.fs(102, 35): [FS0988] Main module of program is empty: nothing will happen when it is run

I checked that answer on SO and adding do() at the end of the last file of Domain.Tests: ValidatePhoneNumberChangeTests.fs didn't do anything.

What can I do to get rid of this warning?

3 Answers

@rmunn is on the right track in the comments. <OutputType> defaults to Library when TargetFramework is netstandardXX or net4XX, and Exe when TargetFramework is netcoreappXX.

Setting <OutputType>Library</OutputType> is IMO the best way to fix this, rather than adding an entry point that won't be called.

<TargetFramework>netcoreapp2.2</TargetFramework>

This specifies the Domain.Tests project as an executable

If you only need it to be a class library then change it to

<TargetFramework>netstandard2.0</TargetFramework>

If you simply want to remove the warning you can add a main method by either adding this at the end of ValidatePhoneNumberChangeTests.fs or in a Program.fs at the end of the compilation order

[<EntryPoint>] 
let main argv =
    0

Just remove the Program.fs and OutputType (it doesn't work for me as well). Set GenerateProgramFile to true in PropertyGroup like that:

<PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <IsPackable>false</IsPackable>
    <GenerateProgramFile>true</GenerateProgramFile>
</PropertyGroup>

cheers!

Related