How to generate F# signature file (without Visual Studio)

删除回忆录丶 提交于 2021-02-11 04:51:44

问题


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

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.

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


回答1:


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.

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>

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.)



来源:https://stackoverflow.com/questions/58781292/how-to-generate-f-signature-file-without-visual-studio

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!