How to create a C# executable with . NET Core?

Asked

Viewed 2,204 times

-1

I’m developing an introduction material to programming using . NET Core. I have read the documentation regarding the creation and execution of projects for the web, but I haven’t found anything that addresses how to create a console application project and generate a .EXE.

I figured with the namespace ConsoleApplication the code would generate an executable, but in fact it creates a .DLL which can be executed with dotnet programa.dll.

What should I do for the project to create an executable?

2 answers

1


I found.

First the project should be created with dotnet new -t console

As the default framework is netcoreapp1.0, when dotnet buildis invoked, it will compile Program.cs as a dll. Pair that it Compile an executable:

In the archive project.json, you must navigate to the option "frameworks", open a new line and include “net461”:{}, (with the comma). Remove the option "type": "platform", and add

"runtimes": {     "win7-x64":{}   }

After the declaration of imports. Regenerate the project with dotnet restore. After that, dotnet build compile Project.cs as an executable.

-2

When you create new project you have to choose the "Console Application" option in the project type.

  • Thank you for your reply, but I don’t understand. I use command prompt to invoke dotnet new in the folder where the project will live; how do I choose Console Application as project type?

  • You use Visual Studio to write code?

  • No, for this introductory material project, to be used in low-resource computer labs, I’m going to use Visual Studio Code as an editor. I wanted to tag vscode, but I still don’t have enough reputation in this stackoverflow for this.

  • 1

    I removed the visual-studio tag, no relation to the subject. But I also did not add vscode, because the question is not about Ides, but about how to create the executable application and console, if I understand correctly (I believe that a good answer should not present a solution that works only in an IDE).

  • Completely ridiculous. This has everything to do with the kind of IDE you obviously have. If working with Visual Studio is one way, with VS Code is another, it is ridiculous a right answer to this question and that does not indicate that with Visual Studio Community (Gratis) it is only clikar new console application and not the other. And answer the question. But I abandon the question since perhaps the only one that answers the question without relying on the IDE is "Doing")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.