简体   繁体   中英

ASP.NET Web Application (w/ ascx WebUserControl) as NuGet Package

I'm rather familiar with creating NuGet packages for class libraries. Yesterday i tested doing the same for a ASP.NET Web Application, and to my surprise it worked (kind of - with some quirks).

My Web Application is simple and only contains a single .ascx WebUserControl . My hope was that at the end i would have a DLL containing my control similar to if you were to publish the site and extract the results DLL for the control from the bin of the published site. However this is not quite what happens.

After packing the NuGet package and then using it in other projects, doing so results in the .ascx files fully being "copied" to the project with the NuGet package installed. This .ascx files from the NuGet package can be edited as a normal .ascx file would allow and still references code behind that doesn't exist in the solution.

So there are some issues. My question is - does anyone know of a procedure i can follow that would compile a user control into a DLL that can then be distributed via a NuGet package?

does anyone know of a procedure i can follow that would comile a user control into a DLL that can then be distributed via a NuGet package?

You can convert your usercontrols into custom control, here is a detail document about how to do it.

Turning an ascx user control into a redistributable custom control

The basic steps to make this happen are as follows:

  1. Write your User Control as you normally would, typically using the Visual Studio designer.

  2. Test it using a simple page before trying to deploy it.

  3. Deploy the app to precompile it.

  4. Grab the user control's assembly produced by the deployment step, and you're essentially done: you have your Custom Control.

  5. Finally, use your Custom Control in other apps the same way as you always use Custom Control's.

After compile the user control into a DLL, distributed it via a NuGet package should be easy for you.

Hope this can give you some help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM