-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'dotnet new' web item templates (razor view, api controller, mvc …
…controller) (#46714) * add dotnet new templates (razor view, api controller, mvc controller) (#1) * added razor view * fix identity for razor view item template * added api controller * fixed api, added mvc controller * pr comment fixes * PR comment fixes 2 * fixing postActions.description * changed encoding for razor view Index.cshtml
- Loading branch information
1 parent
a11fec5
commit ecc1055
Showing
12 changed files
with
330 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
...ectTemplates/Web.ItemTemplates/content/ApiController/.template.config/dotnetcli.host.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/dotnetcli.host" | ||
} |
9 changes: 9 additions & 0 deletions
9
...Web.ItemTemplates/content/ApiController/.template.config/localize/templatestrings.en.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"author": "Microsoft", | ||
"name": "API Controller", | ||
"description": "API Controller with or without read/write actions", | ||
"symbols/namespace/description": "namespace for the generated code", | ||
"symbols/actions/description": "create controller with read/write actions", | ||
"symbols/actions/displayName": "Add ReadWrite Actions", | ||
"postActions/openInEditor/description": "Opens ValueController.cs in the editor" | ||
} |
58 changes: 58 additions & 0 deletions
58
src/ProjectTemplates/Web.ItemTemplates/content/ApiController/.template.config/template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/template", | ||
"author": "Microsoft", | ||
"classifications": [ "Web", "ASP.NET" ], | ||
"name": "API Controller", | ||
"generatorVersions": "[1.0.0.0-*)", | ||
"description": "API Controller with or without read/write actions", | ||
"tags": { | ||
"language": "C#", | ||
"type": "item" | ||
}, | ||
"groupIdentity": "Microsoft.AspNetCore.Mvc.ApiController", | ||
"precedence": "9800", | ||
"identity": "Microsoft.AspNetCore.Mvc.ApiController.8.0", | ||
"shortName": "apicontroller", | ||
"sourceName": "ValueController", | ||
"primaryOutputs": [ | ||
{ | ||
"path": "ValueController.cs" | ||
} | ||
], | ||
"defaultName": "ValueController", | ||
"symbols": { | ||
"namespace": { | ||
"description": "namespace for the generated code", | ||
"replaces": "MyApp.Namespace", | ||
"type": "parameter" | ||
}, | ||
"actions": { | ||
"description": "create controller with read/write actions", | ||
"displayName": "Add ReadWrite Actions", | ||
"type": "parameter", | ||
"datatype": "bool", | ||
"defaultValue": "false" | ||
}, | ||
"HostIdentifier": { | ||
"type": "bind", | ||
"binding": "HostIdentifier" | ||
}, | ||
"NameIsController": { | ||
"type": "computed", | ||
"value": "(name == \"ControllerBase\")" | ||
} | ||
}, | ||
"postActions": [ | ||
{ | ||
"id": "openInEditor", | ||
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")", | ||
"description": "Opens the created controller in the editor", | ||
"manualInstructions": [ ], | ||
"actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6", | ||
"args": { | ||
"files": "0" | ||
}, | ||
"continueOnError": true | ||
} | ||
] | ||
} |
48 changes: 48 additions & 0 deletions
48
src/ProjectTemplates/Web.ItemTemplates/content/ApiController/ValueController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace MyApp.Namespace | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
#if NameIsController | ||
public class ValuesController : Microsoft.AspNetCore.Mvc.ControllerBase | ||
#else | ||
public class ValuesController : ControllerBase | ||
#endif | ||
{ | ||
#if(actions) | ||
// GET: api/<ValuesController> | ||
[HttpGet] | ||
public IEnumerable<string> Get() | ||
{ | ||
return new string[] { "value1", "value2" }; | ||
} | ||
|
||
// GET api/<ValuesController>/5 | ||
[HttpGet("{id}")] | ||
public string Get(int id) | ||
{ | ||
return "value"; | ||
} | ||
|
||
// POST api/<ValuesController> | ||
[HttpPost] | ||
public void Post([FromBody] string value) | ||
{ | ||
} | ||
|
||
// PUT api/<ValuesController>/5 | ||
[HttpPut("{id}")] | ||
public void Put(int id, [FromBody] string value) | ||
{ | ||
} | ||
|
||
// DELETE api/<ValuesController>/5 | ||
[HttpDelete("{id}")] | ||
public void Delete(int id) | ||
{ | ||
} | ||
#endif | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ectTemplates/Web.ItemTemplates/content/MvcController/.template.config/dotnetcli.host.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/dotnetcli.host" | ||
} |
9 changes: 9 additions & 0 deletions
9
...Web.ItemTemplates/content/MvcController/.template.config/localize/templatestrings.en.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"author": "Microsoft", | ||
"name": "MVC Controller", | ||
"description": "MVC Controller with or without read/write actions", | ||
"symbols/namespace/description": "namespace for the generated code", | ||
"symbols/actions/description": "create controller with read/write actions", | ||
"symbols/actions/displayName": "Add ReadWrite Actions", | ||
"postActions/openInEditor/description": "Opens HomeController.cs in the editor" | ||
} |
58 changes: 58 additions & 0 deletions
58
src/ProjectTemplates/Web.ItemTemplates/content/MvcController/.template.config/template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/template", | ||
"author": "Microsoft", | ||
"classifications": [ "Web", "ASP.NET" ], | ||
"name": "MVC Controller", | ||
"generatorVersions": "[1.0.0.0-*)", | ||
"description": "MVC Controller with or without read/write actions", | ||
"tags": { | ||
"language": "C#", | ||
"type": "item" | ||
}, | ||
"groupIdentity": "Microsoft.AspNetCore.Mvc.MvcController", | ||
"precedence": "9800", | ||
"identity": "Microsoft.AspNetCore.Mvc.MvcController.8.0", | ||
"shortName": "mvccontroller", | ||
"sourceName": "HomeController", | ||
"primaryOutputs": [ | ||
{ | ||
"path": "HomeController.cs" | ||
} | ||
], | ||
"defaultName": "HomeController", | ||
"symbols": { | ||
"namespace": { | ||
"description": "namespace for the generated code", | ||
"replaces": "MyApp.Namespace", | ||
"type": "parameter" | ||
}, | ||
"actions": { | ||
"description": "create controller with read/write actions", | ||
"displayName": "Add ReadWrite Actions", | ||
"type": "parameter", | ||
"datatype": "bool", | ||
"defaultValue": "false" | ||
}, | ||
"HostIdentifier": { | ||
"type": "bind", | ||
"binding": "HostIdentifier" | ||
}, | ||
"NameIsController": { | ||
"type": "computed", | ||
"value": "(name == \"Controller\")" | ||
} | ||
}, | ||
"postActions": [ | ||
{ | ||
"id": "openInEditor", | ||
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")", | ||
"description": "Opens the created controller in the editor", | ||
"manualInstructions": [ ], | ||
"actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6", | ||
"args": { | ||
"files": "0" | ||
}, | ||
"continueOnError": true | ||
} | ||
] | ||
} |
88 changes: 88 additions & 0 deletions
88
src/ProjectTemplates/Web.ItemTemplates/content/MvcController/HomeController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace MyApp.Namespace | ||
{ | ||
#if NameIsController | ||
public class HomeController : Microsoft.AspNetCore.Mvc.Controller | ||
#else | ||
public class HomeController : Controller | ||
#endif | ||
{ | ||
// GET: HomeController | ||
public ActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
|
||
#if(actions) | ||
// GET: HomeController/Details/5 | ||
public ActionResult Details(int id) | ||
{ | ||
return View(); | ||
} | ||
|
||
// GET: HomeController/Create | ||
public ActionResult Create() | ||
{ | ||
return View(); | ||
} | ||
|
||
// POST: HomeController/Create | ||
[HttpPost] | ||
[ValidateAntiForgeryToken] | ||
public ActionResult Create(IFormCollection collection) | ||
{ | ||
try | ||
{ | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
catch | ||
{ | ||
return View(); | ||
} | ||
} | ||
|
||
// GET: HomeController/Edit/5 | ||
public ActionResult Edit(int id) | ||
{ | ||
return View(); | ||
} | ||
|
||
// POST: HomeController/Edit/5 | ||
[HttpPost] | ||
[ValidateAntiForgeryToken] | ||
public ActionResult Edit(int id, IFormCollection collection) | ||
{ | ||
try | ||
{ | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
catch | ||
{ | ||
return View(); | ||
} | ||
} | ||
|
||
// GET: HomeController/Delete/5 | ||
public ActionResult Delete(int id) | ||
{ | ||
return View(); | ||
} | ||
|
||
// POST: HomeController/Delete/5 | ||
[HttpPost] | ||
[ValidateAntiForgeryToken] | ||
public ActionResult Delete(int id, IFormCollection collection) | ||
{ | ||
try | ||
{ | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
catch | ||
{ | ||
return View(); | ||
} | ||
} | ||
#endif | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ProjectTemplates/Web.ItemTemplates/content/RazorView/.template.config/dotnetcli.host.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/dotnetcli.host" | ||
} |
6 changes: 6 additions & 0 deletions
6
...tes/Web.ItemTemplates/content/RazorView/.template.config/localize/templatestrings.en.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"author": "Microsoft", | ||
"name": "Razor View", | ||
"description": "A Razor view without a page model", | ||
"postActions/openInEditor/description": "Opens Index.cshtml in the editor" | ||
} |
40 changes: 40 additions & 0 deletions
40
src/ProjectTemplates/Web.ItemTemplates/content/RazorView/.template.config/template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/template", | ||
"author": "Microsoft", | ||
"classifications": [ "Web", "ASP.NET" ], | ||
"name": "Razor View", | ||
"generatorVersions": "[1.0.0.0-*)", | ||
"description": "Am empty razor view", | ||
"tags": { | ||
"language": "C#", | ||
"type": "item" | ||
}, | ||
"groupIdentity": "Microsoft.AspNetCore.Mvc.RazorView", | ||
"precedence": "9800", | ||
"identity": "Microsoft.AspNetCore.Mvc.RazorView.8.0", | ||
"shortName": "view", | ||
"sourceName": "Index", | ||
"primaryOutputs": [ | ||
{ "path": "Index.cshtml" } | ||
], | ||
"defaultName": "Index", | ||
"symbols": { | ||
"HostIdentifier": { | ||
"type": "bind", | ||
"binding": "HostIdentifier" | ||
} | ||
}, | ||
"postActions": [ | ||
{ | ||
"id": "openInEditor", | ||
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")", | ||
"description": "Opens the created view in the editor", | ||
"manualInstructions": [ ], | ||
"actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6", | ||
"args": { | ||
"files": "0" | ||
}, | ||
"continueOnError": true | ||
} | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
src/ProjectTemplates/Web.ItemTemplates/content/RazorView/Index.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@* | ||
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 | ||
*@ | ||
@{ | ||
} |