Dotnet core framework içerisinde bazı front end kütüphaneleri ve frameworklerini içerek şekilde projeler oluşturmamıza imkan veren proje şablonları barındırıyor.
Bu şablonlardan ilki react. Şablonu kullanarak full-stack bir uygulama oluşturabiliyoruz.
Şablonda react js kütüphanesi ile oluşturulmuş bir frontend uygulama ve ASP.NET Core Web API proje şablonu ile oluşturulmuş bir backend uygulama yer alıyor.
İlk olarak --help opsiyonu ile komutu inceleyelim.
dotnet new react --help
Komutu girdiğimizde karşımıza aşağıdaki gibi bir çıktı geliyor. Şimdi kullanacağımız opsiyonlara bakalım. Hem şablon opsiyonlarını hem de genel opsiyonlardan bazılarını kullanacağız. Bunlar name, output, auth, no https ve proxy port olacak.
--name opsiyonu ile uygulamaya verilecek ismi,
--output opsiyonu ile projenin oluşacağı dizinin yolunu,
--auth opsiyonu ile backend uygulamasında kullanılacak kimlik doğrulama yöntemini,
--no-https ile backend uygulamasında https protokolünü kullanmayacağımızı,
--ProxyPort ile ise front end uygulaması için port numarası belirleyebiliyoruz.
eg@debian:~$ dotnet new react --help
ASP.NET Core with React.js (C#)
Author: Microsoft
Description: A project template for creating an ASP.NET Core application with React.js
Usage:
dotnet new react [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:
-au, --auth <Individual|None> The type of authentication to use
Type: choice
None No authentication
Individual Individual authentication
Default: None
--exclude-launch-settings Whether to exclude launchSettings.json from the generated template.
Type: bool
Default: false
--no-restore If specified, skips the automatic restore of the project on create.
Type: bool
Default: false
-P, --ProxyPort <ProxyPort> Port number to use for the SPA front-end development proxy.
Type: integer
Default: 0
--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
-uld, --use-local-db Whether to use LocalDB instead of SQLite. This option only applies if --auth
Individual or --auth IndividualB2C is specified.
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
--use-program-main Whether to generate an explicit Program class and Main method instead of
top-level statements.
Type: bool
Default: false
Aşağıdaki çıktıdaki gibi komutu girdiğimizde ExampleSolution.ReactApp1 adında /home/eg/Data/DotnetCliExamples/ExampleSolution/ExampleSolution.ReactApp1 dizininde bir ASP.NET Core Web API uygulaması oluşmuş oluyor.
Aynı dizinde ClientApp klasörü içerisinde ise react js ile oluşturulan front end uygulaması yer alıyor.
eg@debian:~$ dotnet new react --name ExampleSolution.ReactApp1 --output /home/eg/Data/DotnetCliExamples/ExampleSolution/ExampleSolution.ReactApp1 --auth None --no-https --ProxyPort 9093
The template "ASP.NET Core with React.js" was created successfully.
Processing post-creation actions...
Restoring /home/eg/Data/DotnetCliExamples/ExampleSolution/ExampleSolution.ReactApp1/ExampleSolution.ReactApp1.csproj:
Determining projects to restore...
Restored /home/eg/Data/DotnetCliExamples/ExampleSolution/ExampleSolution.ReactApp1/ExampleSolution.ReactApp1.csproj (in 1.11 sec).
Restore succeeded.