如何解决“程序的主模块为空:运行时什么也不会发生” [英] How to resolve "Main module of program is empty: nothing will happen when it is run"

查看:76
本文介绍了如何解决“程序的主模块为空:运行时什么也不会发生”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在F#解决方案中有两个项目。

1.具有 [EntryPoint] 并设置为StarUp项目。

2.支持,第二个项目,持有一个小组支持模块。即它们仅被调用,从不启动任何东西,也不用作入口点,StartUp项目也不是。



对于支持项目中的最后一个模块,在Visual Studio中进行编译可得到


警告FS0988:程序主模块为空;
在运行时什么都不会发生


尽管使用编译器选项nowarn 内联为模块中的 #nowarn 988 内联,引起警告确实抑制了该消息,我宁愿添加诸如虚拟功能之类的带有注释的功能来解决该问题。



一个人如何做这样的虚拟功能来解决警告?



EDIT



杰克是正确的,因为我的支持项目设置为控制台应用程序而不是 Class Library 。更改为类库解决了该警告。了解另一种情况下的 do()也很高兴。



EDIT



虽然我将支持项目设置为控制台应用程序似乎很奇怪,但我最近发现由于某种原因,更改为项目中的代码,将输出类型从 Class Library 更改为 Console Application 。我怀疑这与F#PowerPack及其构建规则有关,但这只是一个猜测。

解决方案

是作为还是作为控制台应用程序支持项目? (这是通过项目属性页设置的。)



如果将其构建为库,则可能需要添加 do ()在项目中最后一个文件的末尾。这对于使F#编译器在某些特定情况下感到满意是必要的,例如,当您创建仅包含程序集级属性的模块时(由于将它们应用于程序集,因此该模块在编译器中显示为空)。 / p>

您可以在我的代码中看到一个示例:
https://github.com/jack-pappas/FSharp.Compatibility/blob/master/FSharp.Compatibility.OCaml/AssemblyInfo.fs


I have two projects in an F# solution.
1. main project with [EntryPoint] and set as the StarUp project.
2. support, the second project, holds a group of support modules. I.e. they are only called and never initiate anything nor serve as the entry point nor are the StartUp project.

For the last module in the support project, compiling in Visual Studio gives

warning FS0988: Main module of program is empty; nothing will happen when it is run

While using compiler option nowarn inline as #nowarn "988" in the module causing the warning does suppress the message I would rather add something like a dummy function with comments that resolves the issue.

How does one make such a dummy function to resolve the warning?

EDIT

Jack is correct in that my support project was setup as a Console Application instead of a Class Library. Changing to Class Library resolved the warning. It is also nice to know about do () for the other case.

EDIT

While it seemed odd that I would have set a support project as a Console Application, I recently found that for some reason when I made a change to the code in the project, something changed the Output type from Class Library to Console Application. I suspect it has to do with the F# PowerPack and it's build rules, but it's only a guess.

解决方案

Are you building the support project as a Library or as a Console Application? (This is set via the project properties page.)

If you're building it as a library, then you may need to add a do() at the end of the last file in the project. This is necessary to make the F# compiler happy in a few specific scenarios, like when you create a module which contains only assembly-level attributes (because they're applied to the assembly, the module appears "empty" to the compiler).

You can see an example in my code here: https://github.com/jack-pappas/FSharp.Compatibility/blob/master/FSharp.Compatibility.OCaml/AssemblyInfo.fs

这篇关于如何解决“程序的主模块为空:运行时什么也不会发生”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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