asp.net - 生成 Web 用户控件的 dll

标签 asp.net dll user-controls

如何制作我的 Web 应用程序用户控件的 dll? 我有 usercontrol222.ascx,但我想用这个用户控件制作一个 dll。

最佳答案

创建一个仅包含用户控件(“usercontrol222.ascx”)的项目,并从新项目的部署中获取该控件的 dll。以下是此方法的来源以及更完整的解释:Turning an .ascx User Control into a Redistributable Custom Control (下面是值得注意的摘录,请参阅完整的链接)。

Step 3: Use the Publish Command to Precompile the Site

The next step is to use the new Publish command to precompile your site and turn your user control into a potential custom control. You'll find the command under Build / Publish Web Site. In the Publish dialog, do the following:

  • Pick a Target Location. This is the location on your hard drive that your site will be precompiled to.
  • Deselect "Allow this precompiled site to be updatable". In updatable mode, only the code behind file (if any) would get compiled, and the ascx would be left unprocessed. This is useful in some scenarios, but is not what you want here since you want the resulting DLL to be self-contained.
  • Select "Use fixed naming and single page assemblies". This will guarantee that your user control will be compiled into a single assembly that will have a name based on the ascx file. If you don't check this option, your user control could be compiled together with other pages and user controls (if you had some), and the assembly would receive a random name that would be more difficult to work with.

Step 4: Finding the Resulting Custom Control

Now, using the Windows Explorer or a command-line window, let's go to the directory you specified as the target so we can see what was generated. You will see a number of files there, but let's focus on the one that is relevant to our goal of turning the user control into a custom control.

In the "bin" directory, you will find a file named something like App_Web_MyTestUC.ascx.cdcab7d2.dll. You are basically done, as this file is your user control transformed into a custom control! The only thing that's left to do is to actually use it.

关于asp.net - 生成 Web 用户控件的 dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4391212/

相关文章:

c# - 如何停止包含多个控件的面​​板的闪烁

javafx - 使用 FXML 在用户控件中创建并绑定(bind) DoubleProperty

c# - 在 ELMAH 获取异常之前捕获异常并清除它

c# - 仅在 Gridview 的最后一行显示复选框?

c# - 无法从 C# 调用用 C++ 编写的 dll 函数

javascript - Unity3d : How to use dll from Javascript?

c# - 如何从 C# 将 const char* 传递给 C 函数?

user-controls - Three.js First Person Controls 一直在移动相机

javascript - 从 ASP.NET 调用 Javascript 函数

c# - 如何阻止 EF 尝试更新 SQL Server 的计算列?