我真的不想问这么愚蠢的问题,但我的沮丧情绪已经沸腾了。我有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
工作和工作测试(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
的名称更改为Program.fs
。除了Program.fs
之外的任何名称都有同样的问题。但我发现,如果删除Microsoft.NET.Test.Sdk
包,构建就可以了,但只有在VS.Bizzarre中构建两次之后。我还不知道为什么会发生这种事。
更新:
当您将名称更改为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可以修复此警告,并允许您使用任何文件名。