Skip to content

Add 'dotnet new' web item templates (razor view, api controller, mvc controller) #46714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"$schema": "http://json.schemastore.org/dotnetcli.host"
}
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"
}
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
}
]
}
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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"$schema": "http://json.schemastore.org/dotnetcli.host"
}
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"
}
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
}
]
}
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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"$schema": "http://json.schemastore.org/dotnetcli.host"
}
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"
}
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
}
]
}
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
*@
@{
}