Search code examples
asp.net.netnugetlibrariesasp.net-webpages

Adding NuGet packages / including libraries with ASP .NET Web Pages


As a former classic ASP user, my boss wants to use ASP .NET Web Pages, because he doesn't like MVC or Web Forms.

In the absence of a solution/project, it is possible to somehow install and use NuGet packages (Newtonsoft JSON, log4net, etc...) within an ASP Web Pages "project" (for lack of a better word) ?

If not, is it possible to include other libraries somehow ? I.e including the DLL directly, or any other method ?

I want to be clear on the fact that I'm looking for a way to include third-party already-compiled code, no home-made source files, which I already found out how to do.

Edit

I turned out to create an empty ASP.NET project, i.e supposedly without MVC or Web Forms. That allowed me to add NuGet packages, but apparently now, the code I write into pure "code" files (i.e .vb or .cs files) doesn't seem to work from within views any more. Even if I use fully qualified names (like new TestLib.TestClass.HelloWOrld()), the compiler doesn't find it, while the exact same thing works perfectly from within a view that does not belong to a VS project.


Solution

  • Hum, I did not think that this being web forms, or pre-web forms would matter?

    As long as you open the project with file->open web site, and NOT use a "sln" project file, then nuget should work for you. When you add a nuget to the project, then it should/will/supposed to add the .dll's to the bin folder for you.

    Adding nuget packages to a web forms "web site" , and NOT a application thus should result in required files being added to your bin folder.

    It not clear which project you attempting to add, and you don't mention what .net framework your project is set to run as, but nuget works with a web site project.

    To be fair, the oldest projects I can create now are asp.net web forms, but even creating a empty web site would in theory be quite much the same as the asp.net pages you are using and have now.

    I don't think VS knows the difference.

    Edit:

    So, assuming JUST a web site, not a "application"???

    Then to open such a web site, you do NOT use file->open project, but use file-open->web site

    Ok, so let's do that:

    enter image description here

    Ok, so we browse to that web site folder, select it - there is NOT a project file.

    So, now we have the "site" open.

    Note how we do NOT see project->properties.

    But, we MOST certainly see the manage nuget packages.

    We are 100% free to pick/select/add/enjoy/use nuget packages.

    So, now let's add something.

    Say ghostscript .net (lets me crack open PDF's, create preview thumb's of hte first page of a PDF after a user up-loads a file - nice library!!!).

    So, open the web site. If its NEVER been opened say by vs2022, then you want to save. This WILL cause creating of a .sln file. Now, close, and from that point onwards, you STILl can/should use file->open web site.

    But, now you can use the above manage nuget packages.

    So, this option will/now should work;

    Thus this:

    enter image description here

    So, this:

    enter image description here

    So, I added bootstrap, I added jQuery (don't we all!!!).

    So, now lets add ghostscript:

    enter image description here

    Now KEEP in mind, that vs will detect/know/change how such packages are referanced and installed.

    with a web site application, then of course "packages" are used.

    but, web a site, then .dll's HAVE to be and WILL BE copied to the bin folder for you. (that's quite much how/where .dll and additional assemblies are placed for a web site as opposed to a web site application).