Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include Javascript library with @ sign in .NET core MVC application

Currently I'm working on a .NET core MVC app wired up with yarn to add packages. So far I've added the Signalr package like this: yarn add @microsoft/signalr

Which adds the package to /wwwroot/lib/@microsoft/signalr/etc..

However when I try to include the package in the Web app it gets stuck. I'm including it like this: <script src="lib/@microsoft/signalr/dist/browser/signalr.js"></script>

also <script src="lib/microsoft/signalr/dist/browser/signalr.js"></script> does not work.

Anyone knows how to fix this? We do not want to switch to libman and prefer to keep using packages with Yarn.

Cheers!

like image 380
Niek Avatar asked Dec 16 '25 21:12

Niek


1 Answers

Firstly, you need know that Yarn will not install the client side package to your wwwroot by default.

It globally downloads the package in %UserProfile%\AppData\Local\Yarn\ folder.

In my PC, it exists in C:\Users\username\AppData\Local\Yarn\Cache\v6:

enter image description here

The whole working steps

  1. Be sure you have installed note.js, then run following command to install Yarn :

     npm install --global yarn
    
  2. Run command to add signalr package:

     yarn add @microsoft/signalr
    
  3. Find the signalr package(@microsoft folder) in %LOCALAPPDATA%\Yarn\ and copy the whole @microsoft folder:

    enter image description here

  4. Paste the whole @microsoft folder to your project wwwroot/lib folder:

    enter image description here

  5. Then add the js reference like below:

    <script src="@Url.Content("/lib/@microsoft/signalr/dist/browser/signalr.js")"></script>
    

    enter image description here


Actually I suggest you can use Libman, it can directly download to your wwwroot folder.

like image 143
Rena Avatar answered Dec 19 '25 11:12

Rena



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!