如何生成F#签名文件(不使用Visual Studio) [英] How to generate F# signature file (without Visual Studio)

查看:42
本文介绍了如何生成F#签名文件(不使用Visual Studio)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MacOS上使用JetBrains Rider,并尝试使用Scott Wlaschin的代码功能强大的域建模

I' m using JetBrains Rider on MacOS and experimenting with code from Scott Wlaschin Domain Modelling Made Functional

这是我的模块定义及其相关性:

Here are my module definition and it dependencies:

module internal DomainModeling.Domain.PlaceOrderWorkflow.Internal

open DomainModeling.Domain.Api
open DomainModeling.Domain.Primitives
open DomainModeling.Domain.Utils

我想从此模块生成签名文件.但是我对使用dotnet生成器或fsharp编译器感到困惑.如果使用dotnet命令,则无法传递标志-sig 但是如果我使用像这样的fsharp编译器

I want to generate signature file from this module. But I'm confused of using dotnet builder or fsharp compiler. If I use dotnet command I can't pass flag --sig But if I use fsharp compiler like this

fsharpc src/PlaceOrderWorkflow.fs --sig:PlaceOrderWorkflow.fsi

我得到编译器错误.我认为是因为它不了解我的依赖关系.像这样的错误

I get compiler errors. I think because it doesn't know about my dependencies. Errors like this

error FS0039: The namespace or module 'DomainModeling' is not defined.

所以,请告诉我在这种情况下如何生成* .fsi?

So, please, tell me how to generate *.fsi in this case?

推荐答案

您很可能会遇到此错误,因为您没有将所有源文件传递给F#编译器,而只是传递给单个文件.要生成F#接口文件,编译器需要处理整个项目,因此您需要使用所有源文件以及对您所依赖的所有库的引用来调用 fsharpc .如果您的项目不平凡,那可能会很难.

You are most likely getting this error because you did not pass all source files to the F# compiler, but only a single file. To generate F# interface files, the compier needs to process the entire project, so you'd need to call fsharpc with all source files, but also with references to all libraries that you are depending on. If your project is anything non-trivial, this would probably be quite hard.

但是,您可以在普通的 fsproj 项目文件中指定-sig 参数.我刚刚进行了测试,它似乎也可以与.NET Core一起使用.您可以通过添加 OtherFlags 参数来做到这一点:

However, you can specify the --sig parameter in the normal fsproj project file. I just tested this and it seems to work with .NET Core too. You can do this by adding the OtherFlags parameter:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>    
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DefineConstants>TRACE</DefineConstants>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <OtherFlags>--sig:test.fsi</OtherFlags>
  </PropertyGroup>    
  <ItemGroup>
    <Compile Include="Program.fs" />
  </ItemGroup>   
</Project>

当我指定它并使用 dotnet run 运行我的项目或使用 dotnet build 进行构建时,它将生成带有以下内容的 test.fsi 文件:所有接口.(这是针对整个项目的,但是我认为没有办法将其限制为单个文件的接口.)

When I specify this and run my project using dotnet run or build it using dotnet build, it generates the test.fsi file with all the interfaces. (This is for the whole project, but I don't think there is a way to restrict this to interfaces for a single file.)

这篇关于如何生成F#签名文件(不使用Visual Studio)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆