首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >‘'dotnet build’指定main方法

‘'dotnet build’指定main方法
EN

Stack Overflow用户
提问于 2017-04-12 17:14:16
回答 1查看 7.3K关注 0票数 21

我使用dotnet从命令行构建一个.NET核心C#项目。该项目有多个具有main方法的类。因此,我得到了这个错误:

$ 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命令?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-12 17:41:06

您可以编辑您的csproj以定义要使用的类(在PropertyGroup中):

<StartupObject>foo.Program2</StartupObject>

或通过以下方式在命令行上指定此MSBuild属性:

$ dotnet build foo.csproj -p:StartupObject=foo.Program2

哪里

namespace foo
{
  class Program2{ public static void Main() {} }
}
票数 44
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43365254

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档