1
votes

I've just created a new dotnet core project with the following:

dotnet new webapi

The created the following folders and files:
bin
controllers
obj
wwwroot (empty)
dotnet.csproj
Program.cs
Startup.cs

Now i want to get started with bower (bootstrap, jQuery, angular 1.x) and add static files to my project. But this should be added in wwwroot folder with lib, images, js and css, right? How do i add this to my current project?

I've checked the following link to add static files, but gives me an error: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files#serving-default-files

the type or namespace name 'StaticFiles' does not exist in the name space 'Microsoft.AspNetCore'

Thanks in advance!

2
install node with npm then install bower if you require it. now you can create a bower json file in the wwwroot folder and just bower install it. - Jai
@Jai Gives me the following error: bower ENOENT No bower.json present - Fillah

2 Answers

2
votes

Install bower globally on your system: npm install -g bower

Create .bowerrc file in the root of your application with the following content, this tells bower where to restore files:

{
  "directory": "wwwroot/lib"
}

Initialise bower by running bower init, this will create a bower.json file in the root of you application. You can now start install vendor packages by running a command like the following - nb. you can search for packages at https://bower.io/search/:

bower install jquery --save

To start serving static files from your dotnetcore application run the following:

dotnet add package Microsoft.AspnetCore.StaticFiles

Then in your Startup.cs add the line app.UseStaticFiles(); before the line app.UseMvc();

Restore, build, run and you should be able to access your static files in a url like http://localhost:5000/lib/jquery/dist/jquery.js

0
votes

You need to add Static Files dependency in your project.json file

"Microsoft.AspNetCore.StaticFiles": "1.0.0"