Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

449
Views
'dotnet build' especifica el método principal

Estoy usando dotnet para compilar un proyecto .NET Core C# desde la línea de comandos. El proyecto tiene varias clases con un método main . Por lo tanto me sale el 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.

Pasar el interruptor /main da como resultado el 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

¿Cómo puedo pasar el interruptor /main al comando dotnet ?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puede editar su csproj para definir qué clase usar (dentro de un PropertyGroup ):

 <StartupObject>foo.Program2</StartupObject>

o especifique esta propiedad de MSBuild en la línea de comando a través de:

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

dónde

 namespace foo { class Program2{ public static void Main() {} } }
about 4 years ago · Santiago Trujillo Report

0

Solo para agregar por qué falla llamar a dotnet con /main con ese error, tenga en cuenta que dice " Compilar con /main "; /main es un parámetro para el compilador ( csc.exe ), no paradotnet build . dotnet build invocará MSBuild.exe que, a su vez, invocará csc.exe , pero deberá indicarle a dotnet build cuál es la clase de inicio para que pueda indicar csc.exe . Esto es lo que hace la respuesta aceptada.

Alternativamente, si estuviera llamando a csc.exe directamente, podría pasarle /main así...

 csc.exe Program.cs Test.cs /main:TestNamespace.Test
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!