Blazor - how to install nuget packages into project folder - nuget

I have a simple Blazor application - I need to install jQuery, however, when I use the NuGet package manager to do so in Visual Studio 2019 it is installing a reference to the package where the package is placed in c:\users....
I have Visual Studio options for NuGet set to packages.config in package management and I was expecting to get a packages file in the Blazor code directory.
I need the jQuery to be accessible site relative (so under wwwroot\js or something like that).
Does anyone know how to get VS/Blazor to do this?

Why don't just use CDN? Just add this line to your index.html (in client project)
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
Or you can choose from here
Or you can download the file and place it somewhere inside your wwwroot folder.
Also this question may be helpful.

Related

Create a NuGet package with only javascript files

I want to create a NuGet package that contains only javascript. I have no assembly that needs to be built and included.
So to do this I created an empty solution in vs, and created an empty project. In the project I created a Scripts directory with my javascript files. I have a package.nuspec and a packages.config
When I run "nuget pack" commandline I get an error:
C:\MyProject>nuget
pack
Attempting to build package from 'TestProject.csproj'.
MSBuild auto-detection: using msbuild version '16.1.76.45076' from
'C:\Program Files (x86)\Microsoft Visual
Studio\2019\Enterprise\MSBuild\Current\bin'.
Error NU5012: Unable to find 'C:\MyProject\TestProject.exe'. Make sure the project has been built.
C:\MyProject>
If I try to build the project in visual studio, I get an error...
Program does not contain a static 'Main' method suitable for an entry
point.
...which makes sense because I made this from an empty project.
I am not trying to deploy the assembly, just javascript, can I stop it from trying to build somehow?
Don't use a project. Have have your .nuspec and javascript files in the directory, then run nuget pack. If the nuspec doesn't contain a <files> section, then it will just copy the filesystem structure directly into the nupkg.
Having said that, new ASP.NET Core projects from Microsoft's templates no longer use front end resources (html, javascript, css) from NuGet packages, but rather use either LibMan or npm, to be more in-line with what the non-.NET front-end ecosystem uses. I suggest investigating those technologies and using them if possible.

Installing NuGet packages to custom folder in a project in Visual Studio 2015

I have a Visual Studio 2015 solution with many projects. For one of the projects I would like the files from NuGet to download to a specific folder in my project. For example, I intend to use Bootstrap and also Signalr. I would like Bootstrap to download everything into one folder in my application, and not create folders within my project root. For example, I have a folder called 'Libs' in the project and would like those libraries to use 'Libs' as their root folder. This is due to an external build solution that handles everything in the 'Libs' folder.
I've found these docs about using a NuGet.config folder for the solution, but this does not handle my problem. Any ideas?
As far as I'm aware, this isn't possible. Each Nuget package is written with specific instructions on how to install into a project. One of those instructions is where to put files, another example would be what transform to apply to the web.config. Nuget doesn't specify a way to modify these instructions. The only thing you could do would be to modify the packages yourself - download the .nupkg file and open it up as a zip file, you will be able to edit the folder structure from there.

How can I create a solution level NuGet package for an entire project?

I have created a NuGet gallery in my company.
I want to create and publish a solution level NuGet package.
Everyone who will install the package will not get a dll but an entire project added to his/her visual studio solution.
Just like adding an existing project, the user will get a project with source code classes and everything is ready to use.
Just build it and use it.
I know it's possible, but couldn't find any documentation.
Anyone?
It is possible to add any files (not only .dll) and even directory structures to a NuGet package, so in theory you could store all files belonging to a project in a package and publish that. However, it is only possible to install NuGet packages into an existing project, meaning that you won't be able to add the packaged files as new project to any solution. In addition, the contained files will be put to the solution's packages folder, not to a solution or project folder.
As an alternative, consider creating a Template project instead of a NuGet package, as explained in How to: Create Project Templates and my blog post Creating template projects. This will result in a .vsix file that any developer can install as Visual Studio Add-In, the templated project will then appear in Visual Studio's File -> New -> Project... dialog as new project type and can be added to any solution.
Similar to your NuGet gallery, it is also possible to create a private Visual Studio Gallery to share such Add-Ins within, for example, a company, as explained in this MSDN article.

How to package 2 third-party dll's

I'm reading through the nuget documentation and I don't completely understand how nuget works.
I have 2 third party dll's that I have been asked to turn into a nuget package, so that our local developers can just install them to a project via nuget. This would be something that we would host locally.
Does this mean I just create a project in vs and drop the dll's in the project or do I use something like the package explorer.
I apologize in advance if this is a silly question, however I am an absolute beginner when it comes to Nuget, etc..
Any tips would be greatly appreciated.
The simplest and fastest way to get a nuget package up and running is to just fire up package explorer --> create a new package --> drag and drop your dlls into the "Package Contents" area, it'll ask you whether you want the dlls in the "lib" folder, which you do --> create a bit of metadata about the package, ie give it a description and version and whatnot, and then just save it.
After you save it, you can then copy the .nupkg file to a shared location - the file system on a centralised server is fine if you have access to one, and then setup access to this "feed" (ie, the shared folder) in visual studio (tools --> options --> Package Manager --> Package Sources), thus:
Or if you want to host the packages over http you can follow the instructions here: https://github.com/NuGet/NuGetGallery/blob/master/README.markdown.
Other option would be to use Nuget.exe spec, pack commands to quickly create package.
More details here # http://docs.nuget.org/docs/reference/command-line-reference

nuget package inside

I understand how to build dll nuget package
I would like to build a JavaScript nuget package of my own. I would like to learn how jQuery nuget package being constructed/installed by nuget.
How do I know how jQuery (or similar nuget package) nuget package being constructed? Especially I would like to know how these *.js being copied/ installed to specific folder (scripts) of a ASP.net MVC project
Thanks
NuGet uses a convention-over-configuration approach. This is what makes it easy to inject some files (images, code, javascript, etc) into a specific folder of a target Visual Studio project.
You can simply open a .nupkg file with any zip-utility (e.g. 7zip) and extract the archive to see its contents.
A NuGet package can have 3 folders: lib, content & tools.
Anything in the content folder will be injected into the target project using the same relative path to the project root as to the content folder of the nuget package.
More info here: http://docs.nuget.org/docs/creating-packages/package-conventions
Also with respect to how jQuery or other similar Javascript libraries are packaged, here are some pointers.
The list of public jQuery/jQuery plugins that have been "NuGetified" can be see here http://nuget.org/packages?q=jquery The jQuery NuGet package page http://nuget.org/packages/jQuery has a note saying that it is maintained by the NuGet Community Packages project.
If you go to the CodePlex project at http://nugetpackages.codeplex.com/ and browse the source code, you'll find it contains a couple of sub projects. These are NuGet package projects for the respective open source (mainly Javascript) projects.
You will notice that they simply include the relevant pure Javascript packages, e.g. jquery-1.8.3.js, jquery-1.8.3.min.js, etc. in the Content/Scripts path.