Because Visual Studio Code is folder-based and not project-based like Visual Studio, it does not have a File | New Project option in its list of menus.
Instead, you'll use Yeoman to scaffold a basic empty ASP.NET project. If you do not already have npm installed, complete the following steps:
C:MyBootstrap4Site
. npm install -g yo grunt-cli generator-aspnet bower
After Yeoman and supporting tools have been installed, follow these steps:
yo aspnet
Bootstrap4Site
and press Enter. dnu restore
C:MyBootstrap4Site
folder.Currently, the project is simply an empty ASP.NET project that will only show a Hello World message when run. You'll need to enable your project and MVC to serve static files by completing the following tasks:
project.json
file and change the dependencies
and tools array to the following:"dependencies": { "Microsoft.NETCore.App": { "version": "1.0.0", "type": "platform" }, "Microsoft.AspNetCore.Diagnostics": "1.0.0", "Microsoft.AspNetCore.Mvc": "1.0.0", "Microsoft.AspNetCore.Razor.Tools": { "version": "1.0.0-preview2-final", "type": "build" }, "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", "Microsoft.AspNetCore.StaticFiles": "1.0.0", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", "Microsoft.Extensions.Configuration.CommandLine": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0", "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0" }, "tools": { "BundlerMinifier.Core": "2.0.238", "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final", "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" }
dotnet restore
ConfigureServices
method in the Startup.cs
class file to the following, in order to enable MVC:public void ConfigureServices(IServiceCollection services) { services.AddMvc(); }
Configure
method in the Startup.cs
class file to the following:public void Configure(IApplicationBuilder app) { app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
Since an empty project was created, no default controller or view would have been created by default. You've already configured a default route in the previous steps and in order for it to work you'll need to add a Home controller and an Index view:
Controllers
and add another folder called Views
.Home
and Shared
inside the newly created Views
folder.Controllers
folder and select New File from the context menu. Name the file HomeController.cs.
HomeController.cs
file:using Microsoft.AspNetCore.Mvc; namespace BS4App.Controllers { public class HomeController : Controller { public IActionResult Index() { return View(); } } }
Index.cshtml
to the ViewsHome
folder and set its content to the following:<h1>This is my Bootstrap 4 site. </h1>
3.15.186.79