dotnet new console

Bu komut ile ilk proje şablomunuz olan console ile bir uygulama oluşturacağız. İlk olarak --help opsiyonu ile komut hakkında bilgi alalım.

dotnet new console --help

Komutu --help opsiyonu ile birlikte kullandığımızda karşımıza aşağıdaki gibi çıktı gelecektir. Çıktıda açıklama kısmında üç farklı işletim sisteminde (linux, windows ve macos) çalışan bir komut satırı projesi şeklinde bir bilgi mevcut.

eg@debian:~$ dotnet new console --help
Console App (C#)
Author: Microsoft
Description: A project for creating a command-line application that can run on .NET on Windows, Linux and macOS

Usage:
  dotnet new console [options] [template options]

Options:
  -n, --name <name>       The name for the output being created. If no name is specified, the name of the output 
                          directory is used.
  -o, --output <output>   Location to place the generated output.
  --dry-run               Displays a summary of what would happen if the given command line were run if it would 
                          result in a template creation.
  --force                 Forces content to be generated even if it would change existing files.
  --no-update-check       Disables checking for the template package updates when instantiating a template.
  --project <project>     The project that should be used for context evaluation.
  -lang, --language <C#>  Specifies the template language to instantiate.
  --type <project>        Specifies the template type to instantiate.

Template options:
  -f, --framework <net6.0|net7.0>  The target framework for the project.
                                   Type: choice
                                     net7.0  Target net7.0
                                     net6.0  Target net6.0
                                   Default: net7.0
  --langVersion <langVersion>      Sets the LangVersion property in the created project file
                                   Type: text
  --no-restore                     If specified, skips the automatic restore of the project on create.
                                   Type: bool
                                   Default: false
  --use-program-main               Whether to generate an explicit Program class and Main method instead of 
                                   top-level statements.
                                   Type: bool
                                   Default: false

To see help for other template languages (F#, VB), use --language option:
   dotnet new console -h --language F#

dotnet new console --name <console_app_name> --output <output_directory> --use-program-main

Yukarıda çıktıda yer alan bazı opsiyonları kullanarak örnek bir uygulama oluşturalım. Kullanacağımız opsiyonlar name, output ve use program main opsiyonları olacak.

--name opsiyonu ile uygulamaya verilecek ismi,

--output opsiyonu ile projenin oluşacağı dizinin yolunu,

--use-program-main ile ise program sınıfı oluşturup içinde main metodu yer alacak şekilde uygulama başlangıç noktası belirleme şansımız bulunuyor.

Eğer bunu kullanmazsak, program sınıfı ve içinde main metodu oluşmuyor. Bunun yerine yeni gelen top-level statement özelliğini kullanıyoruz.

Aşağıdaki çıktıdaki gibi komutu girdiğimizde ExampleSolution.Console1 adında /home/eg/Data/DotnetCliExamples/ExampleSolution/ExampleSolution.ConsoleApp1 dizininde console uygulamamız oluşmuş oluyor.

eg@debian:~$ dotnet new console --name ExampleSolution.ConsoleApp1 --output /home/eg/Data/DotnetCliExamples/ExampleSolution/ExampleSolution.ConsoleApp1 --use-program-main
The template "Console App" was created successfully.

Processing post-creation actions...
Restoring /home/eg/Data/DotnetCliExamples/ExampleSolution/ExampleSolution.ConsoleApp1/ExampleSolution.ConsoleApp1.csproj:
  Determining projects to restore...
  Restored /home/eg/Data/DotnetCliExamples/ExampleSolution/ExampleSolution.ConsoleApp1/ExampleSolution.ConsoleApp1.csproj (in 42 ms).
Restore succeeded.

Last updated