首页 > 解决方案 > 但它是:“EntryPointAttribute”属性必须是最后一个文件中的最后一个声明

问题描述

我真的很讨厌问这样一个愚蠢的问题,但我的挫败感正在沸腾。我按此顺序有 3 个文件:

Work.fs
WorkTests.fs
Main.fs

这就是 Main.fs 的全部内容

module Main 
open Work

    [<EntryPoint>]
    let main args =
        let p = work "some data"
        printfn "p : %A" p
        0

Work and WorkTests (xunit) 排在第一位,通过后我添加了 Main.fs

我仍然收到最后一个声明/文件错误。

我尝试了很多东西,但无济于事。

例如,如果我省略“模块 Main”,我会得到“只有最后一个源文件......可能会省略这样的声明”

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

    <PropertyGroup>
        <TargetFramework>netcoreapp3.0</TargetFramework>
        <OutputType>Exe</OutputType>
        <IsPackable>false</IsPackable>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
        <Tailcalls>true</Tailcalls>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
        <PackageReference Include="xunit" Version="2.4.1" />
        <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
        <PackageReference Include="FsUnit.xUnit" Version="4.0.4" />
    </ItemGroup>

    <ItemGroup>
        <Compile Include="Work.fs" />
        <Compile Include="WorkTests.fs" />
        <Compile Include="Main.fs" />
    </ItemGroup>

</Project>

标签: f#

解决方案


我能够重现该问题。唯一解决它的是将名称更改为Main.fsto Program.fs。除此以外的任何名称Program.fs都有相同的问题。但我发现如果你删除Microsoft.NET.Test.Sdk包构建工作,但只有在 VS 中构建两次之后。奇怪。我还不知道为什么会这样。


更新:

当您将名称更改为时,会Program.fs出现另一个构建警告:A 'Program.fs' file can be automatically generated for F# .NET Core test projects. To fix this warning, either delete the file from the project, or set the <GenerateProgramFile> property to 'false'..

添加<GenerateProgramFile>false</GenerateProgramFile>到 FSPROJ 可修复此警告并允许您使用任何文件名。


推荐阅读