What does compilationOptions.emitEntryPoint mean?

随声附和 提交于 2019-11-28 11:53:27

As mentioned below: It looks like it is a flag to the compiler to indicate that the project is a console application vs. a library (namely: a console application must contain public static void Main())

You can see from the source here.

In the new RC1 default web application template, you'll notice at the bottom of Startup.cs there is a new expression bodied method that acts as the entry point:

public static void Main(string[] args) => WebApplication.Run<Startup>(args);

If you remove this method then perform a build (dnu build) you will get an error:

error CS5001: Program does not contain a static 'Main' method suitable for an entry point

However, if you change the emitEntryPoint flag to false and attempt to build again, it will succeed. This is because it is creating a library instead of a console app.

I see this in the source;

var outputKind = compilerOptions.EmitEntryPoint.GetValueOrDefault() ?
    OutputKind.ConsoleApplication : OutputKind.DynamicallyLinkedLibrary;

Looks like it tells the compiler whether to create a Console Application or a Library.

Additionaly, if you create a new Class Library (Package) and Console Application (Package) in VS2015 you'll see that project.json for the Console Application includes the following, while the Class Library does not;

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