Dotnet core framework içerisinde bir çok web uygulaması inşa edebileceğimiz şablon bulunmaktadır. Bunlardan ilki olan web şablonunu inceleyelim.
dotnet new web --help
İlk olarak her zaman yaptığımız gibi --help opsiyonunu kullanalım. Komutu girdiğimizde çıktısı aşağıdaki gibi olacaktır. Komutun açıklama kısmında da belirtildiği gibi boş bir ASP.NET Core Web uygulaması oluşturmak için bu komutu kullanabiliriz.
eg@debian:~$ dotnet new web --help
ASP.NET Core Empty (C#)
Author: Microsoft
Description: An empty project template for creating an ASP.NET Core application. This template does not have any content in it.
Usage:
dotnet new web [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:
--exclude-launch-settings Whether to exclude launchSettings.json from the generated template.
Type: bool
Default: false
-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
--no-restore If specified, skips the automatic restore of the project on create.
Type: bool
Default: false
--no-https Whether to turn off HTTPS. This option only applies if Individual,
IndividualB2C, SingleOrg, or MultiOrg aren't used for --auth.
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#), use --language option:
dotnet new web -h --language F#
dotnet new web --name <web_app_name> --output <output_directory> --no-https --kestrelHttpPort <port_number>
Şimdi kullanacağımız opsiyonlara bakalım. Hem şablon opsiyonlarını hem de genel opsiyonlardan bazılarını kullanacağız. Bunlar name, output, no https ve kestrel http port (opsiyon listesinde belirtilmemiş ancak kullanılabiliniyor.) olacak.
--name opsiyonu ile uygulamaya verilecek ismi,
--output opsiyonu ile projenin oluşacağı dizinin yolunu,
--no-https ile https protokolünü kullanmayacağımızı,
--kestrelHttpPort ile ise uygulama çalıştığı esnada kullanılacak, varsayılan olarak gelen kestrel sunucusunun http port numarasını belirleyebiliyoruz.
Aşağıdaki çıktıdaki gibi komutu girdiğimizde ExampleSolution.WebApp1 adında /home/eg/Data/DotnetCliExamples/ExampleSolution/ExampleSolution.WebApp1 dizininde boş bir ASP.NET Core Web uygulaması oluşmuş oluyor.
eg@debian:~$ dotnet new web --name ExampleSolution.WebApp1 --output /home/eg/Data/DotnetCliExamples/ExampleSolution/ExampleSolution.WebApp1 --no-https --kestrelHttpPort 9090
The template "ASP.NET Core Empty" was created successfully.
Processing post-creation actions...
Restoring /home/eg/Data/DotnetCliExamples/ExampleSolution/ExampleSolution.WebApp1/ExampleSolution.WebApp1.csproj:
Determining projects to restore...
Restored /home/eg/Data/DotnetCliExamples/ExampleSolution/ExampleSolution.WebApp1/ExampleSolution.WebApp1.csproj (in 45 ms).
Restore succeeded.