1

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Virus721
  • 8,061
  • 12
  • 67
  • 123
  • What makes you think working with NuGet packages in ASP.NET Web Pages is any different from working with them in Web Forms or MVC? Do you know how to install and manage NuGet packages in those types of apps? What's preventing you from doing the same in Web Pages? – mason Dec 05 '22 at 18:14
  • @mason I'm pretty sure I mentionned I have no solution/project files. – Virus721 Dec 06 '22 at 08:17
  • Sounds to me like you're using Web Forms Web Site Project. See the difference between Web Site vs Web Application as it relates to Web Forms [here](https://stackoverflow.com/questions/398037/asp-net-web-site-or-asp-net-web-application). – mason Dec 06 '22 at 13:58
  • Linking this in, I had a similar issue and this had the answer - https://stackoverflow.com/questions/47843907/nuget-package-install-error-invalid-uri-the-authority-host-could-not-be-pars TL;DR later versions of VS require a workaround where you have to manually edit the sln – Bondolin Jun 21 '23 at 20:51

1 Answers1

1

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).

Albert D. Kallal
  • 42,205
  • 3
  • 34
  • 51
  • Thanks for your answer, but I don't have a project file. That's what ASP web pages are, if I understood correctly, just pages in the form of aspx files, just like if it was PHP.If I can't add NuGet packages, is there a way to manually reference DLLs ? Thanks. – Virus721 Dec 06 '22 at 08:16
  • @Virus721 It sounds like you do indeed have Web Forms, just in the form of a Web Site instead of a Web Application project. I'm not aware of Web Pages having views in the form of .aspx pages, just .cshtml. Of course, that's an ancient framework that wasn't heavily used, so documentation and experience on it are hard to come by. The modern equivalent would be [ASP.NET Core Razor Pages](https://learn.microsoft.com/en-us/aspnet/core/razor-pages), probably something you should look into. – mason Dec 06 '22 at 13:53
  • See my new edit. I show how neGet packages can be added to a web site. No question that you open as web site. (maybe dirty some file). Now, save the project. it WILL create a sln file for you, but you STILL continue to use open->web site. Do NOT use open project. And if you do this, then the nuget package manager will work (so until a .sln file exists, nuget GUI options will not work). See above new Edit and screen shots as to how this works. – Albert D. Kallal Dec 06 '22 at 18:58
  • @AlbertD.Kallal Thanks for you answer. I could successfully add and use the NewtonSoft.Json buget package. I've had a lot of weird behaviours (i.e the solution successfully compiling once, and then showing an error after the first debug session, visual studio saving the solution to the user's home folder instead of the folder I chose to open, etc). But despite that, it works, I can now debug (attach to IIS process), use nuget packages, inclure source code files, include DLLs, etc. I can't seem to be able to compile the solution, but it works without the need for that, so I'll just ignore it. – Virus721 Jan 04 '23 at 15:46