F#:命名空间未定义

Eho*_*ret 5 f# namespaces module compilation

我的 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
Run Code Online (Sandbox Code Playgroud)

这会导致两个错误:

  • Behaviour.fs(3, 20): [FS0039] The namespace 'Domain' is not defined.->open Rm.Accounting.Domain.Commands
  • Behaviour.fs(4, 20): [FS0039] The namespace 'Domain' is not defined.->open Rm.Accounting.Domain.Events

如果没有该文件Behaviour.fs,项目就可以编译,我不确定为什么这两个导入会引起一些麻烦。

Eho*_*ret 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>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

重新组织 fsproj,成功了:

<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>
Run Code Online (Sandbox Code Playgroud)

  • 我以前在 Visual Studio 中见过这种行为(我知道您正在使用 Rider,但仅供参考)。 (2认同)