简体   繁体   English

ASP.NET Web应用程序(带有ascx WebUserControl)作为NuGet包

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

I'm rather familiar with creating NuGet packages for class libraries. 我对为类库创建NuGet包非常熟悉。 Yesterday i tested doing the same for a ASP.NET Web Application, and to my surprise it worked (kind of - with some quirks). 昨天,我测试了对ASP.NET Web应用程序执行相同的操作,但令我惊讶的是它确实有效(有点怪异)。

My Web Application is simple and only contains a single .ascx WebUserControl . 我的Web应用程序很简单,只包含一个.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. 我希望最后,我将拥有一个包含我的控件的DLL,就像您要发布该站点并从已发布的站点的bin中提取该控件的结果DLL一样。 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. 打包NuGet程序包,然后在其他项目中使用它之后,这将导致.ascx文件完全“复制”到安装了NuGet程序包的项目中。 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. 可以按常规.ascx文件允许的方式编辑NuGet包中的.ascx文件,并且仍然引用解决方案中不存在的背后代码。

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? 我的问题是-是否有人知道我可以遵循的程序,该程序会将用户控件编译为DLL,然后可以通过NuGet程序包分发该程序?

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? 有谁知道我可以遵循的将用户控件编译成DLL的程序,然后可以通过NuGet程序包分发该程序?

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 将ascx用户控件转换为可再发行的自定义控件

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. 通常,通常使用Visual Studio设计器来编写用户控件。

  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. 将用户控件编译成DLL后,通过NuGet软件包分发它对您来说应该很容易。

Hope this can give you some help. 希望这可以为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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