本文介绍了'dotnet build' 指定主要方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 dotnet
从命令行构建 .NET Core C# 项目.该项目有多个带有 main
方法的类.因此我得到错误:
I am using dotnet
to build a .NET Core C# project from the command line. The project has multiple classes with a main
method. Thus I get the error:
$ dotnet build
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.
Test.cs(18,28): error CS0017: Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.
Build FAILED.
传递 /main
开关导致错误:
Passing the /main
switch results in the error:
$ dotnet build /main:Test
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.
MSBUILD : error MSB1001: Unknown switch.
Switch: /main:Test
如何将 /main
开关传递给 dotnet
命令?
How can I pass the /main
switch to the dotnet
command?
推荐答案
您可以编辑您的 csproj 以定义要使用的类(在 PropertyGroup
内):
You can edit your csproj to define which class to use (inside a PropertyGroup
):
<StartupObject>foo.Program2</StartupObject>
或通过以下方式在命令行上指定此 MSBuild 属性:
or specify this MSBuild property on the command line via:
$ dotnet build foo.csproj -p:StartupObject=foo.Program2
哪里
namespace foo
{
class Program2{ public static void Main() {} }
}
这篇关于'dotnet build' 指定主要方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!