本文介绍了'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开关会导致错误:

$ 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

这篇关于'dotnet build'指定主要方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 22:45