I've done this using a regular .cs file that just extends System.Web.UI.UserControl and then included the assembly of the project that contains the control into other projects. I've also created .ascx files in one project then copied all ascx files from a specified folder in the properties->Build Events->Pre-build event.
Now what I want to do is a combination of those two: I want to be able to use ascx files that I build in one project, in all of my other projects but I want to include them just using assembly references rather than having to copy them to my "secondary" projects as that seems a ghetto way to accomplish what I want to do. It works yes, but it's not very elegant.
Can anyone let me know if this even possible, and if so, what the best way to approac开发者_StackOverflow社区h this is?
Fundamentally, user controls were never meant to be shared across projects. If you want to create controls that are reusable across projects, you should create server controls that are compiled into a DLL which can simply be referenced by other projects.
Developing Custom ASP.NET Server Controls
This article: http://webproject.scottgu.com/CSharp/UserControls/UserControls.aspx has a useful pre-build idea which can copy the controls needed during development.
copy $(SolutionDir)\MyUserControlLibrary*.ascx $(ProjectDir)\UserControls\
I know this question has already been answered, but one of our clients uses SiteFinity and we provide user controls with a compiled dll file that they then configure in their CMS system. It works quite well, as far as I can tell.
To do so, we create the user control in an asp.net web site (not a web application), and publish the site using the precompile and "used fixed assembly names" option. We then distribute the dll associated with the ascx file to the client and they import as necessary.
精彩评论