Click here to Skip to main content
13,732,877 members
Click here to Skip to main content
Add your own
alternative version

Stats

4.7K views
2 bookmarked
Posted 4 Jun 2018
Licenced CPOL

Creating RazorPage Apps Using the CLI

, 4 Jun 2018
Rate this:
Please Sign up or sign in to vote.
Creating RazorPage apps using the CLI

While I was creating a recent test application with Razor Pages, I found myself clicking the "new file" button in VS Code too many times when I wanted to add a new Page.

vscode new file

I really love the .NET CLI and with every release, there seems to be something I discover that has been added to either the core functionality or the templates. Running dotnet new this time around, I fell upon the page template...

what is this?

Within your application, run dotnet new page and a new Razor Page is added to the project. See the -h|--help some items removed for brevity.

$ dotnet new page -h

  -n, --name          The name for the output being created. If no name is specified, 
                      the name of the current directory is used.
  -o, --output        Location to place the generated output.

Razor Page (C#)  
Author: Microsoft  
Description: A Razor page with or without a page model  
Options:  
  -na|--namespace     namespace for the generated code
                      string - Optional
                      Default: MyApp.Namespace

  -np|--no-pagemodel  create page without a PageModel
                      bool - Optional
                      Default: false / (*) true


* Indicates the value used if the switch is provided without a value.

Given this information, I was able to quickly add a new page.

Should this be a default setting in the CLI? See Issue# 9194.

$ dotnet new page -n Index -na myapp.Pages.Area -o Pages/Area

Creating a variable for the namespace made this shorter.

$ ns=-na=myapp.Pages

Then I can just create a new page using the shorter command.

$ dotnet new page -n Index $ns.Area -o Pages/Area

Razor Pages is a super easy way to get going on web app and now adding the additional pages too using the CLI is just as easy. Looking forward to some of the other scaffolding pieces making it into the CLI as well as the previous yo aspnet functionality I helped build back in the beta days.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Shayne P Boyer
United States United States
I work on Azure, ASP.NET Core content and Open Source, speak at national and community events while helping teams architect web and cloud applications.

You may also be interested in...

Pro
Pro

Comments and Discussions

 
SuggestionCool, then what about... Pin
Alaa Ben Fatma4-Jun-18 7:02
professionalAlaa Ben Fatma4-Jun-18 7:02 
GeneralRe: Cool, then what about... Pin
Shayne P Boyer5-Jun-18 7:09
memberShayne P Boyer5-Jun-18 7:09 
GeneralRe: Cool, then what about... Pin
Alaa Ben Fatma5-Jun-18 7:59
professionalAlaa Ben Fatma5-Jun-18 7:59 
GeneralRe: Cool, then what about... Pin
Shayne P Boyer6-Jun-18 2:19
memberShayne P Boyer6-Jun-18 2:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180920.1 | Last Updated 4 Jun 2018
Article Copyright 2018 by Shayne P Boyer
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid