如何共享在ASP.NET Web应用程序之间的用户控件?

问题描述:

这问题是一个跟进我对sharing Web应用程序之间的资源的,因为我还没有找到一个好的解决办法。

This question is a follow up to my question about sharing resources between web applications, because I have not yet found a good solution.

我有由其他三个Web应用程序共享的用户控件和资源的Web应用程序。

I have a web application with user controls and resources that are shared by three other web applications.


Solution
|
+-CommonControlsWebApp
| +- resources
| |  +- images
| |  +- scripts
| |  +- stylesheets
| +- UserControls
| 
+-WebApp1
| 
+-WebApp2
| 
+-WebApp3

这是我所知道的这么远:

This is what I know this far:


  • 我不能编译CommonControlsWebApp成一个DLL,因为我创建的用户控件。这是唯一可能与自定义服务器控件,这里的一切是在code隐藏文件。所以,我需要一种方法来共享四个项目之间的ASCX文件。
  • 从CommonControlsWebApp将文件复制到其他三个项目在Solution Explorer不更新他们的文件。我会当一个文件被添加或CommonControls改名为'添加exting项目在所有三个WebApps的一切。
  • 更改到网站模式将解决这个问题,但我担心编译时间WebApp1-3如果我这样做。
  • 添加为链接的目录不起作用。
  • 我可以使用Subversion共享项目之间的文件,但我相信,这将需要我检查进出再次所有的时间文件,如果我开发我必须通过的一个测试用户控件WebApps的。
  • I can not compile CommonControlsWebApp into a single dll since I am creating user controls. This is only possible with custom server controls, where everything is in the code-behind file. So I need a way to share the ascx files between the four projects.
  • Copying the files from CommonControlsWebApp into the three other projects does not update their files in the solution explorer. I would have to 'add exting items' all in all three WebApps when a file is added or renamed in CommonControls.
  • Changing to the Web Site model would remedy this, but I am worried about the compile time for WebApp1-3 if I do this.
  • 'Add as link' does not work for directories.
  • I could use Subversion to share the files between the projects, but i believe that this would require me to check the files in and out again all the time if I am developing a user control that I have to test through one of the WebApps.

那么它是否真的是真实的,ASP.NET不具备一个很好的解决方案?怎么样,你们举办大型的Web应用程序?

编辑:非常感谢所有的答案。我要与生成事件复制我的用户控件现在,再看看我们是否有时间将它们重构为服务器控件。

Thanks a lot for all the answers. I am going to copy my user controls with a build event for now, and then see if we have time to refactor them into server controls.

我们做这件事我的present公司的方法是确保CommonControlsWebApp
 是一个WebApplication的,而不是一个网站。然后你使用名字,这将有助于识别它作为常见的是从个人的Web应用程序不同的文件夹。 (CommonUserControls而不只是用户控件)

The way we do it at my present company is to make sure CommonControlsWebApp is a WebApplication, not a web site. Then you use names for the folders that would help identify it as the common ones that are distinct from the individual web apps. (CommonUserControls instead of just UserControls)

在您的其他网络应用程序,您创建一个虚拟目录到CommonUserControls等,并基于引用添加文件到CommonControlsWebApp.dll

In your other web apps, you create a virtual directory to the CommonUserControls, etc, and add a file based reference to the CommonControlsWebApp.dll

这需要您使用IIS发展(而不是卡西尼),和Visual Studio不会相信这些控件真的存在,但它会在运行时工作,你可以建立只是约blahblah.ascx或仅警告罚款blahblah.master路径无效。

This requires you to use IIS for development (not casini), and Visual Studio won't believe that the controls really exist, but it will work at runtime, and you can build just fine with only warnings about blahblah.ascx or blahblah.master path invalid.

如果你使用普通的母版页和Visual Studio 2008中,您将需要SP1于2008年,并使用__fallback.master在单个Web项目的根去到设计模式。

If you do use common master pages and Visual Studio 2008, you will need SP1 for 2008 and use a __fallback.master in the root of the individual web projects to go in to design mode.

不过,我看到这个在另一个线程,而我要考虑做更多的是这样的:
http://webproject.scottgu.com/CSharp/UserControls/UserControls.aspx

However, I saw this on another thread, and I am going to look into doing more like this: http://webproject.scottgu.com/CSharp/UserControls/UserControls.aspx