F#: 命名空间未定义

5

我有一个 F# 项目 Rm.Accounting.Domain,包含以下文件(按照顺序):

  • Model.fs: module Rm.Accounting.Domain.Model
  • Commands.fs: module Rm.Accounting.Domain.Commands
  • Events.fs: module Rm.Accounting.Domain.Events

最后一个文件 Behaviour.fs 导致了问题。

module Rm.Accounting.Domain.Behaviour

open Rm.Accounting.Domain.Commands
open Rm.Accounting.Domain.Events
open Rm.Accounting.Infrastructure

let a = 42

这导致了两个错误:
  • Behaviour.fs(3, 20): [FS0039] The namespace 'Domain' is not defined. -> 打开 Rm.Accounting.Domain.Commands
  • Behaviour.fs(4, 20): [FS0039] The namespace 'Domain' is not defined. -> 打开 Rm.Accounting.Domain.Events
没有那个文件Behaviour.fs,项目可以编译。我不确定为什么这两个导入会引起一些麻烦。

你的项目中这些文件是以什么顺序列出的? - Fyodor Soikin
@FyodorSoikin,就像我在帖子中指定的那样。 - Natalie Perret
@FyodorSoikin "还有最后一个引起问题的文件 Behaviour.fs:" - Natalie Perret
1
你怎么知道它们是按照那个顺序排列的? - Fyodor Soikin
@FyodorSoikin 我在Rider中手动排序了它们。 - Natalie Perret
显示剩余2条评论
1个回答

5

感谢评论,看起来尽管在Rider中重新排序文件,但fsproj没有得到正确更新的原因可能有些问题。

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

    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <Compile Include="Behaviour.fs" />
        <Compile Include="Model.fs" />
        <Compile Include="Commands.fs" />
        <Compile Include="Events.fs" />
    </ItemGroup>

    <ItemGroup>
      <ProjectReference Include="..\Rm.Accounting.Infrastructure\Rm.Accounting.Infrastructure.fsproj" />
    </ItemGroup>

</Project>

enter image description here

Re-organising the fsproj, did the trick:

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

    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <Compile Include="Model.fs" />
        <Compile Include="Commands.fs" />
        <Compile Include="Events.fs" />
        <Compile Include="Behaviour.fs" />
    </ItemGroup>

    <ItemGroup>
      <ProjectReference Include="..\Rm.Accounting.Infrastructure\Rm.Accounting.Infrastructure.fsproj" />
    </ItemGroup>

</Project>

2
我之前在Visual Studio中见过这种行为(我知道你正在使用Rider,但只是提供信息)。 - Jim Foye
@JimFoye,这很好知道,以防在VS中发生相同的行为,我会知道该去哪里寻找。 - Natalie Perret
1
我在 VS Code 中也刚刚得到了这个。 - AlignedDev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接