I am building a webpage using ASP.NET Core v2 and would like to use font-awesome.
First let me say that I have tried several things. like installing Bower from NPM, installing font-awesome from NPM, installing font-awesome from Bower packages in VS but nothing seem to work.
can someone please provide the correct way to install font-awesome, (preferred without using a lot of console commands or manual copying of files.)
This is what my depedencises currently looks like
I would recommend using LibMan for this (Short documentation how to use it).
I wrote it manually, bet you could add it through "Add -> Client-Side Library". Here is mine libman.json
{
"version": "1.0",
"defaultProvider": "cdnjs",
"libraries": [
{
"library": "font-awesome#4.7.0",
"destination": "wwwroot/lib/font-awesome",
"files": [
"css/font-awesome.min.css",
"fonts/fontawesome-webfont.eot",
"fonts/fontawesome-webfont.svg",
"fonts/fontawesome-webfont.ttf",
"fonts/fontawesome-webfont.woff",
"fonts/fontawesome-webfont.woff2",
"fonts/FontAwesome.otf"
]
}
]
}
Bower is going away. NuGet now focus on .NET packages so your best bet to get font-awesome is via NPM.
1.Download NPM
Make sure you have the latest nodejs installed. Navigate to https://nodejs.org/en/ and download the LTS version.
To check the version of node as well as npm installed on your machine:
Right click your project in Visual Studio
Select "Open Command Line"
Select "Default (Cmd)" (or whatever command prompt you want to use)
Run command node -v and npm -v
2. Add package.json
You need to have the npm configuration file to your project. This configuration file lists out all your packages and is used by npm to restore packages when it needs to.
To add the npm configuration file:
Right click your project in visual studio
Select "Add" -> "New Item"
Select "ASP.NET Core" on the left and search "npm" on the search bar on the top right
Hit "Add"
3. Install font-awesome (and others)
Open package.json and under devDependencies, just by typing "font-awesome":, it should automatically give you a list of available versions you can pick. Pick a version you like.
By saving this package.json file, the npm will download the libraries listed into the hidden node_modules folder under your project.
4. Copy files to wwwroot
In ASP.NET Core MVC applications, if you want to use static contents like styles and javascript files, beside you need to enable app.UseStaticFiles(); in the Startup.cs, you also need to copy the files to the wwwroot folder. By default, the content, for example, in node_modules are not serviceable to your application.
You can of course manually cope the files you want into wwwroot folder. But then you will have to replace the files whenever there are new versions come out.
To properly copy the files, we need to use 3rd party tooling!
BundlerMinifier is a great tool you can use to bundle files you want and output them to the directories you want. It uses similar configuration file called bundleconfig.json:
But this tool doesn't work well with file types other than .css and .js. There is also an issue of relative url to the font-awesome fonts folder because the font-awesome style uses url(); (setting "adjustRelativePaths": false doesn't always work).
5. Create Gulp tasks
To properly move font-awesome files and fonts to wwwroot folder, I can use gulp to set up tasks I can run before build, after build, etc:
5.1. Install gulp (and rimraf, the unix command rm -rf)
Go to package.json and type gup and rimraf in the dependency list. Save the file.
5.2. Add gulpfile.js to your project and define tasks
I basically need to create a task to move font-awesome to wwwroot/libs folder, and create another task to do the reverse for cleanup. I omitted other tasks not related to font-awesome.
5.2.1 UPDATE for Gulp +v4.0:
gulp from gulp v4.0 Use gulp.series() to combine multiple tasks
so if you are using Gulp +v4.0 you should update your code as below:
gulp.task('default', gulp.series(
'copy:font-awsome'
));
gulp.task('clean', gulp.series(
'clean:font-awesome'
));
5.3 Run tasks
After you have setup the gulpfile.js, you should be able to see the tasks listed in "Task Runner Explorer". If you don't have that window in Visual Studio, Go to "View" -> "Other Windows".
You can manually run any task by right clicking it and hit "Run". Or you can have it run automatically when before build, after build, clean or project open.
After you setup the bindings, a header would be added to the gulpfile.js:
Now save the gulpfile.js file and build your project. Your font-awesome files and fonts should be automatically moved to the wwwroot and ready to use.
I am using ASP.NET Core 2.0.8, on Windows 10, and just struggled to get FA in to my project too. I was able to add it to NPM by adding it to the package.json (as others have mentioned) under dependencies, like this:
{
"version": "1.0.0",
"name": "asp.net",
"private": true,
"devDependencies": {},
"dependencies": {
"bootstrap": "^4.1.1",
"font-awesome": "4.7.0",
"jquery": "^3.3.1",
"popper.js": "^1.14.3"
}
}
Unfortunately, although it restored the package, it didn't deploy the css files where I had expected, so that I could reference them. I don't believe the following is anything like the "correct" way to do it (still learning!), however, it worked for me.
In Solution Explorer:
Navigate to Dependencies > npm
Right-Click font-awesome > Open in File Explorer
Go in to the css folder
Copy the .css files
Back in Visual Studio, in Solution Explorer, navigate to wwwroot
Right-Click css > Open in File Explorer
Paste in the files
You can now drag these in to your project to make references to them, and start using Font Awesome, like this:
_Layout.cshtml:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>#ViewData["Title"] websiteTitle</title>
<environment include="Development">
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="~/css/site.css" />
<link href="~/css/font-awesome.css" rel="stylesheet" />
</environment>
<environment exclude="Development">
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/4.1.1/css/bootstrap.min.css"
asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
<link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
</environment>
</head>
Hope this is of some help to anyone stopping by like I was.
Go to package.json
add the following tag "font-awesome": "^4.7.0" in dependencies section
Eg :-
{
"name": "imsy-app",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/animations": "^5.2.0",
"#angular/common": "^5.2.0",
"#angular/compiler": "^5.2.0",
"#angular/core": "^5.2.0",
"#angular/forms": "^5.2.0",
"#angular/http": "^5.2.0",
"#angular/platform-browser": "^5.2.0",
"#angular/platform-browser-dynamic": "^5.2.0",
"#angular/router": "^5.2.0",
"angular2-moment": "^1.9.0",
"core-js": "^2.4.1",
"ng2-toasty": "^4.0.3",
"ng5-breadcrumb": "0.0.6",
"rxjs": "^5.5.6",
"zone.js": "^0.8.20",
"font-awesome": "^4.7.0"
},
"devDependencies": {
"#angular/cli": "1.6.6",
"#angular/compiler-cli": "^5.2.0",
"#angular/language-service": "^5.2.0",
"typescript": "~2.5.3"
}
}
As a recommendation from Microsoft
The recommended way to install client-side dependencies like Bootstrap
in ASP.NET Core is via Bower (using bower.json)
Open the bower.json file and add font-awesome to the dependencies
{
"name": "ASP.NET",
"private": true,
"dependencies": {
"Font-Awesome": "4.3.0"
}
}
Open the .bowerrc file under bower.json, The directory property is set to wwwroot/lib which indicates the location Bower will install the package assets.
{
"directory": "wwwroot/lib"
}
Now you can refer font-awesome as below
<link href="/lib/font-awesome/css/font-awesome.css" rel="stylesheet" />
The easiest way to get started with Font Awesome is to add a reference to it, using its public content delivery network (CDN) location:
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
For more details:
https://learn.microsoft.com/en-us/aspnet/core/client-side/bower
No coding is necessary using this approach in Visual Studio.
Select the web project in Solution explorer and right click and choose Add and then Client-Side Library. This will also add the necessary content to libman.json file.
Choose Unpkg and then search for : Font Awesome.
Just select version 4.7 like this for example (Click on picture to zoom in):
After that you can add icons like in this example in a Razor file:
<button class="btn btn-success col-md-3 offset-3"><i class="fa-cloud-download fa"></i> Load data</button>
Note that we use 'fa' and then we can add the icons with CSS classes starting with 'fa-'.
Easy !
Disclaimer: This might work best in VS 2019, not VS 2017..
I would like to use https://github.com/MrRio/jsPDF in my ember project.
I wanted to import jsPDF as dependency, therefore I started this way:
bower install git#github.com:MrRio/jsPDF.git --save
Unfortunately, I cannot install files from plugins directory, because "plugins/*" directory is ignored in bower.json file.
I have tried overriding it this way, but without success.
"overrides": {
"jspdf": {
"ignore": [
"**/.*",
"libs",
"CNAME",
"jspdf.js",
"examples/jspdf.PLUGINTEMPLATE.js",
"todo.txt",
"wscript.py",
"build.sh",
"test",
"tools"
]
}
}
Could you please help me?
I just added a jsPDF plugins package to bower.
You can add all the plugins via
bower install jsPDF-plugins --save
Maybe I don't understand SemVer syntax or maybe I don't understand bower (I have version 1.4.1), but I have an app whose bower.json is:
{
"name": "MyApp",
"description": "My AngularJS Project....",
"version": "0.0.0",
"homepage": "https://github.com/angular/angular-seed",
"license": "MIT",
"private": true,
"dependencies": {
"angular": "1.3.x",
"angular-route": "1.3.x",
"angular-loader": "1.3.x",
"angular-mocks": "~1.3.x",
"angular-ui-grid": "~3.0.0-rc.20",
"angular-spinkit": "~0.3.3",
"angular-bootstrap": "0.13.0",
"bootstrap": "3.3.4",
"angular-animate": "~1.3.x",
"file-saver.js": "~1.20150507.2"
},
"resolutions": {
}
}**
When I do a 'bower update', it is “unable to find a suitable version for angular”, but I don't understand why not. Here's the output (#1 seems to be the problem):
Unable to find a suitable version for angular, please choose one:
1) angular#>=1.2.16 <=1.3.x which resolved to 1.2.28 and is required by angular-ui-grid#3.0.0-rc.22
2) angular#1.3.16 which resolved to 1.3.16 and is required by angular-animate#1.3.16, angular-loader#1.3.16, angular-mocks#1.3.16, angular-route#1.3.16
3) angular#1.3.x which resolved to 1.3.16 and is required by MyApp
4) angular#>=1.3.0 which resolved to 1.3.16 and is required by angular-bootstrap#0.13.0
5) angular#* which resolved to 1.3.16 and is required by angular-spinkit#0.3.3
So my reading of that output is that all packages would be happy with version 1.3.16 of angular, except for angular-ui-grid (“resolved to 1.2.28”) But why? Isn't 1.3.16 >=1.2.16 <=1.3.x ? And so isn't version 1.3.16 of Angular a suitable version? isn't it the ONLY suitable version? or maybe I'm misunderstanding what bower is trying to tell me.
I do understand that I can select one of the choices and even add a '!' to persist my choice, but I don't understand why a choice is needed.
Thanks
c0bra - thanks for setting up that plunker - it helped me to easily verify what I believe I finally (after lots of digging) determined is the problem:
there seems to be a bug in older versions of semver.js - I traced down, down, down into the code and the <=1.3.x gets morphed into <=1.3.0-0, and that means that 1.3.16 fails that test.
But that bug has been fixed in the NPM-delivered semver module - I was able to use your plunker to demonstrate to myself that 1.3.16 passes the test with 'latest' semver code, just as you set it up, but fails when I switch to older versions of semver (e.g. "^2.3.0", which seems to be what the bower package requires in its packages.json).
But even the latest bower on github seems to have that ^2.3.0 dependency for semver. So I'll see if I can submit a request to whoever maintains bower to get that upgraded. But I do not see much activity on bower/github of late.
In the meantime, I guess I'm stuck with being forced to answer the question above, since I'm using NPM to get bower, I don't think I can easily override it's semver dependency.
Is there any way to install modules by directly downloading from git-hub without php composer.phar. Because my php composer is not working.
this is the error
$ php composer.phar require webino/webino-image-thumb:2.*
./composer.json has been updated
Loading composer repositories with package information
Ignoring unknown parameter "server role"
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Can only install one of: zf-commons/zfc-admin[v0.1.0, dev-master].
- Can only install one of: zf-commons/zfc-admin[v0.1.0, dev-master].
- Installation request for zf-commons/zfc-admin 0.1.0 -> satisfiable by zf-commons/zfc-admin[v0.1.0].
- Installation request for zf-commons/zfc-admin == 9999999-dev -> satisfiable by zf-commons/zfc-admin[dev-master].
Installation failed, reverting ./composer.json to its original content.
My composer.json looks like this:
{
"name": "zendframework/skeleton-application",
"description": "Skeleton Application for ZF2",
"license": "BSD-3-Clause",
"keywords": [ "framework", "zf2" ],
"minimum-stability": "dev",
"homepage": "framework.zend.com/",
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "2.2.0",
"webino/webino-image-thumb": "1.*",
"zf-commons/zfc-admin":"0.1.0"
}
}
There are three ways you can typically install Zend 2 Modules.
Through the file system
Git
Composer
You could just run:
https://github.com/ZF-Commons/ZfcAdmin.git
to get the module. But I am unsure if it is going to work since you likely have a dependency issue that needs resolving. I would recommend sticking with composer. Please post your whole composer.json file and I'm sure that the issue can be solved.
I cannot reproduce your error.
I copy your composer.json file into an empty directory and execute composer install there. Works.
I then issue composer require webino/webino-image-thumb:2.*, and it downloads that version (2.0.0-RC1) just fine.
I updated from 0.8.0 (I guess) or later to 0.8.5 and bower seems stuck when i do a simple bower install. It happens on my machine and with my cloudbees hosted jenkins.
I tried to do a bower clean-cache, a bower install --force and a rm -rf ~/.bower with no luck.
It always gets stuck on copying instructions such as :
bower copying /home/bigx/.bower/cache/require/34f0965def4ee39276726c265c9162b6
or any other lib, there is no pattern.
I've got the following when I try to reinstall bower (only on my machine not on cloudbees):
npm WARN unmet dependency /usr/lib/node_modules/modulus/node_modules/prompt/node_modules/winston requires pkginfo#'0.2.x' but will load
npm WARN unmet dependency /usr/lib/node_modules/modulus/node_modules/prompt/node_modules/pkginfo,
npm WARN unmet dependency which is version 0.3.0
And here is my component.json
{
"dependencies": {
"angular": "~1.0.5",
"require": "~2.1.4",
"jquery": "~1.9.1",
"angular-sanitize": "~1.0.5",
"foundation": "http://foundation.zurb.com/files/foundation-3.2.5.zip",
"less.js": "~1.3.3",
"font-awesome": "~3.0.2"
},
"devDependencies": {
"angular-mocks": "~1.0.5"
}
}
Any idea?
Regards,
Xavier
Ok so it's a bug of the unzip library used by bower
See here: https://github.com/twitter/bower/issues/314