f# - 但它是:“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>
解决方案
我能够重现该问题。唯一解决它的是将名称更改为Main.fs
to 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 可修复此警告并允许您使用任何文件名。
推荐阅读
- php - 从电子邮件链接自动登录
- prolog - 我在将列表列表放入单个列表时遇到问题
- node.js - LinkedIn:通过消息或连接请求获取我与之交互的用户的基本信息
- java - 复合键和 spring-data-jdbc
- debugging - Dymola 将翻译日志打印到文件
- java - 在 postgresql java 的这个会话中还没有定义序列“testsequence”
- powershell-3.0 - 批量创建 Azure 管理组
- java - 包含 & indexOf 不适用于字母数字字符串
- javascript - 如何将对象数组作为输入参数传递给 kendo 多选下拉 ajax 调用
- swift - 如何在不崩溃的情况下向 UIView 实例的子视图添加约束?