ASP.NET 用户控件编译为 DLL
我在 VS2010 中有一个标准网站项目和一个 Web 部署项目。我已经使用这个项目和部署包大约 4 年了,没有出现任何问题。
部署包已设置为“将所有页面和控制输出合并到单个程序集中”。
这个设置已经有 3-4 年没有出现过问题了,直到现在! 在网站的最新版本中,我添加了一个包含一些页面的文件夹和另一个包含 3 个用户控件的文件夹。现在,当我构建部署包时,3 个用户控件中的 2 个会编译到它们自己的 dll 中,其余的将按预期进行编译。我已经检查了所有三个控件页面后面的代码中的命名空间,它们都是相同的,并且找不到任何地方告诉编译器编译这两个控件而不是其他控件?
我的控件位于命名空间 G2F.Forms.Controls.FormDefintitionListItemControl (反映文件夹结构和控件名称)中。
我有一个页面需要获取对这些控件之一的引用并使用:
.FindControl("IdName") as MyControl
当使用网站或运行项目时,代码一切正常,但当您编译网站时,代码会出现问题上面返回 null,因为该控件现在的类型为 ASP.forms_controls_formdefinitionlistitemcontrol_ascx。
该控件和另一个控件是唯一以这种方式编译的控件,解决方案中还有大约 40-50 个其他控件。
I have a standard web site project and a web deployment project in VS2010. I've been using this project and deployment package for about 4 years now without problems.
The Deployment package has been set to 'Merge all pages and control outputs to a single assembly'.
Not had a problem with this set-up for 3-4 years, until now!
In the newest version of the web site I've added a folder with some pages and another folder with 3 user controls in. Now when I build the deployment package 2 of the 3 user controls compile into their own dll's, the rest compile as expected. I've checked the namespace in the code behind pages of all three controls and they are all the same and can't find anywhere where it would be telling the compiler to compile these two controls and not the others?
My control is in Namespace G2F.Forms.Controls.FormDefintitionListItemControl (which reflects the folder structure and control name).
I have a page that needs to get a reference to one of these controls and uses:
.FindControl("IdName") as MyControl
The code all works fine when using the web site or running the project but when you compile the web site the code above returns null, because the control is now of type ASP.forms_controls_formdefinitionlistitemcontrol_ascx.
This and one other control are the only ones compiling in this way and there are about 40-50 other controls in the solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我的上一条评论,我通过将网站转换为 Web 应用程序找到了一个解决方案,这样做时会遇到很多问题,但最终经过大量排序命名空间和相当多的编译以获得正确的部署设置(设置“允许这个预编译站点要更新”检查!)我让它工作了。
这看起来有点极端,但花了 4 天时间来追查错误并进行重建,能够让它再次工作真是太好了!
As per my last comment I found a solution by converting the web site to a web application, there are loads of gotcha's when doing this but eventually after lots of sorting namespaces and a fair few compiles to get the deployment settings right (set the "Allow this precomiled site to be update" checked!) I got it working.
It seems a bit extreme but having lost 4 days chasing the error and rebuilding it's nice to be able to get it working again!