Skip to content

Commit a337e4f

Browse files
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
1 parent cb780be commit a337e4f

File tree

12 files changed

+330
-0
lines changed

12 files changed

+330
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"$schema": "http://json.schemastore.org/dotnetcli.host"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"author": "Microsoft",
3+
"name": "API Controller",
4+
"description": "API Controller with or without read/write actions",
5+
"symbols/namespace/description": "namespace for the generated code",
6+
"symbols/actions/description": "create controller with read/write actions",
7+
"symbols/actions/displayName": "Add ReadWrite Actions",
8+
"postActions/openInEditor/description": "Opens ValueController.cs in the editor"
9+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"$schema": "http://json.schemastore.org/template",
3+
"author": "Microsoft",
4+
"classifications": [ "Web", "ASP.NET" ],
5+
"name": "API Controller",
6+
"generatorVersions": "[1.0.0.0-*)",
7+
"description": "API Controller with or without read/write actions",
8+
"tags": {
9+
"language": "C#",
10+
"type": "item"
11+
},
12+
"groupIdentity": "Microsoft.AspNetCore.Mvc.ApiController",
13+
"precedence": "9800",
14+
"identity": "Microsoft.AspNetCore.Mvc.ApiController.8.0",
15+
"shortName": "apicontroller",
16+
"sourceName": "ValueController",
17+
"primaryOutputs": [
18+
{
19+
"path": "ValueController.cs"
20+
}
21+
],
22+
"defaultName": "ValueController",
23+
"symbols": {
24+
"namespace": {
25+
"description": "namespace for the generated code",
26+
"replaces": "MyApp.Namespace",
27+
"type": "parameter"
28+
},
29+
"actions": {
30+
"description": "create controller with read/write actions",
31+
"displayName": "Add ReadWrite Actions",
32+
"type": "parameter",
33+
"datatype": "bool",
34+
"defaultValue": "false"
35+
},
36+
"HostIdentifier": {
37+
"type": "bind",
38+
"binding": "HostIdentifier"
39+
},
40+
"NameIsController": {
41+
"type": "computed",
42+
"value": "(name == \"ControllerBase\")"
43+
}
44+
},
45+
"postActions": [
46+
{
47+
"id": "openInEditor",
48+
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
49+
"description": "Opens ValueController.cs in the editor",
50+
"manualInstructions": [ ],
51+
"actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6",
52+
"args": {
53+
"files": "0"
54+
},
55+
"continueOnError": true
56+
}
57+
]
58+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.AspNetCore.Mvc;
3+
4+
namespace MyApp.Namespace
5+
{
6+
[Route("api/[controller]")]
7+
[ApiController]
8+
#if NameIsController
9+
public class ValuesController : Microsoft.AspNetCore.Mvc.ControllerBase
10+
#else
11+
public class ValuesController : ControllerBase
12+
#endif
13+
{
14+
#if(actions)
15+
// GET: api/<ValuesController>
16+
[HttpGet]
17+
public IEnumerable<string> Get()
18+
{
19+
return new string[] { "value1", "value2" };
20+
}
21+
22+
// GET api/<ValuesController>/5
23+
[HttpGet("{id}")]
24+
public string Get(int id)
25+
{
26+
return "value";
27+
}
28+
29+
// POST api/<ValuesController>
30+
[HttpPost]
31+
public void Post([FromBody] string value)
32+
{
33+
}
34+
35+
// PUT api/<ValuesController>/5
36+
[HttpPut("{id}")]
37+
public void Put(int id, [FromBody] string value)
38+
{
39+
}
40+
41+
// DELETE api/<ValuesController>/5
42+
[HttpDelete("{id}")]
43+
public void Delete(int id)
44+
{
45+
}
46+
#endif
47+
}
48+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"$schema": "http://json.schemastore.org/dotnetcli.host"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"author": "Microsoft",
3+
"name": "MVC Controller",
4+
"description": "MVC Controller with or without read/write actions",
5+
"symbols/namespace/description": "namespace for the generated code",
6+
"symbols/actions/description": "create controller with read/write actions",
7+
"symbols/actions/displayName": "Add ReadWrite Actions",
8+
"postActions/openInEditor/description": "Opens HomeController.cs in the editor"
9+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"$schema": "http://json.schemastore.org/template",
3+
"author": "Microsoft",
4+
"classifications": [ "Web", "ASP.NET" ],
5+
"name": "MVC Controller",
6+
"generatorVersions": "[1.0.0.0-*)",
7+
"description": "MVC Controller with or without read/write actions",
8+
"tags": {
9+
"language": "C#",
10+
"type": "item"
11+
},
12+
"groupIdentity": "Microsoft.AspNetCore.Mvc.MvcController",
13+
"precedence": "9800",
14+
"identity": "Microsoft.AspNetCore.Mvc.MvcController.8.0",
15+
"shortName": "mvccontroller",
16+
"sourceName": "HomeController",
17+
"primaryOutputs": [
18+
{
19+
"path": "HomeController.cs"
20+
}
21+
],
22+
"defaultName": "HomeController",
23+
"symbols": {
24+
"namespace": {
25+
"description": "namespace for the generated code",
26+
"replaces": "MyApp.Namespace",
27+
"type": "parameter"
28+
},
29+
"actions": {
30+
"description": "create controller with read/write actions",
31+
"displayName": "Add ReadWrite Actions",
32+
"type": "parameter",
33+
"datatype": "bool",
34+
"defaultValue": "false"
35+
},
36+
"HostIdentifier": {
37+
"type": "bind",
38+
"binding": "HostIdentifier"
39+
},
40+
"NameIsController": {
41+
"type": "computed",
42+
"value": "(name == \"Controller\")"
43+
}
44+
},
45+
"postActions": [
46+
{
47+
"id": "openInEditor",
48+
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
49+
"description": "Opens HomeController.cs in the editor",
50+
"manualInstructions": [ ],
51+
"actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6",
52+
"args": {
53+
"files": "0"
54+
},
55+
"continueOnError": true
56+
}
57+
]
58+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace MyApp.Namespace
4+
{
5+
#if NameIsController
6+
public class HomeController : Microsoft.AspNetCore.Mvc.Controller
7+
#else
8+
public class HomeController : Controller
9+
#endif
10+
{
11+
// GET: HomeController
12+
public ActionResult Index()
13+
{
14+
return View();
15+
}
16+
17+
#if(actions)
18+
// GET: HomeController/Details/5
19+
public ActionResult Details(int id)
20+
{
21+
return View();
22+
}
23+
24+
// GET: HomeController/Create
25+
public ActionResult Create()
26+
{
27+
return View();
28+
}
29+
30+
// POST: HomeController/Create
31+
[HttpPost]
32+
[ValidateAntiForgeryToken]
33+
public ActionResult Create(IFormCollection collection)
34+
{
35+
try
36+
{
37+
return RedirectToAction(nameof(Index));
38+
}
39+
catch
40+
{
41+
return View();
42+
}
43+
}
44+
45+
// GET: HomeController/Edit/5
46+
public ActionResult Edit(int id)
47+
{
48+
return View();
49+
}
50+
51+
// POST: HomeController/Edit/5
52+
[HttpPost]
53+
[ValidateAntiForgeryToken]
54+
public ActionResult Edit(int id, IFormCollection collection)
55+
{
56+
try
57+
{
58+
return RedirectToAction(nameof(Index));
59+
}
60+
catch
61+
{
62+
return View();
63+
}
64+
}
65+
66+
// GET: HomeController/Delete/5
67+
public ActionResult Delete(int id)
68+
{
69+
return View();
70+
}
71+
72+
// POST: HomeController/Delete/5
73+
[HttpPost]
74+
[ValidateAntiForgeryToken]
75+
public ActionResult Delete(int id, IFormCollection collection)
76+
{
77+
try
78+
{
79+
return RedirectToAction(nameof(Index));
80+
}
81+
catch
82+
{
83+
return View();
84+
}
85+
}
86+
#endif
87+
}
88+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"$schema": "http://json.schemastore.org/dotnetcli.host"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"author": "Microsoft",
3+
"name": "Razor View",
4+
"description": "A Razor view without a page model",
5+
"postActions/openInEditor/description": "Opens Index.cshtml in the editor"
6+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"$schema": "http://json.schemastore.org/template",
3+
"author": "Microsoft",
4+
"classifications": [ "Web", "ASP.NET" ],
5+
"name": "Razor View",
6+
"generatorVersions": "[1.0.0.0-*)",
7+
"description": "Am empty razor view",
8+
"tags": {
9+
"language": "C#",
10+
"type": "item"
11+
},
12+
"groupIdentity": "Microsoft.AspNetCore.Mvc.RazorView",
13+
"precedence": "9800",
14+
"identity": "Microsoft.AspNetCore.Mvc.RazorView.8.0",
15+
"shortName": "view",
16+
"sourceName": "Index",
17+
"primaryOutputs": [
18+
{ "path": "Index.cshtml" }
19+
],
20+
"defaultName": "Index",
21+
"symbols": {
22+
"HostIdentifier": {
23+
"type": "bind",
24+
"binding": "HostIdentifier"
25+
}
26+
},
27+
"postActions": [
28+
{
29+
"id": "openInEditor",
30+
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
31+
"description": "Opens Index.cshtml in the editor",
32+
"manualInstructions": [ ],
33+
"actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6",
34+
"args": {
35+
"files": "0"
36+
},
37+
"continueOnError": true
38+
}
39+
]
40+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@*
2+
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
3+
*@
4+
@{
5+
}

0 commit comments

Comments
 (0)