gpt4 book ai didi

c# - 'dotnet build' 指定主要方法

转载 作者:可可西里 更新时间:2023-11-01 07:42:48 25 4
gpt4 key购买 nike

我正在使用 dotnet 从命令行构建一个 .NET Core 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 命令?

最佳答案

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

<StartupObject>foo.Program2</StartupObject>

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

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

在哪里

namespace foo
{
class Program2{ public static void Main() {} }
}

关于c# - 'dotnet build' 指定主要方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43365254/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com