如何在Visual Studio中的Web应用程序之间共享通用的Web资源? [英] How do I share common web resources between web applications in Visual Studio?

查看:77
本文介绍了如何在Visual Studio中的Web应用程序之间共享通用的Web资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个Web应用程序项目,它们共享一个通用的自定义服务器控件库.共享文件后面的代码很容易-它们被编译成一个dll,我在其他项目中使用项目引用来引用.但是,如何处理JavaScript,样式表和图像等文件?我正在尝试以"Visual Studio方式"进行操作,以便尽可能容易地理解和调试.

当前设置如下:

CommonControlsWebApp+-自定义控件+-资源+-图片+-脚本+-样式表WebApp1+-资源*WebApp2+-资源*WebApp3+-资源*

*)IIS中的虚拟目录.

每个Web应用程序上的虚拟目录都指向我的CommonControlsWebApp中的资源目录.这是在IIS中配置的.Visual Studio无法理解此链接,因此调试需要我手动附加到IIS进程.

另一种解决方案是使用WebResourceAttribute将所有资源都包含在通用dll中.但是,当我查看网页的源代码时,这会将 src 链接转换为WebResource.axd?d = GUID之类的东西,恐怕这会使调试变得非常混乱.

第三个解决方案是使用Subversion在所有三个解决方案中包括相同的文件.团队中没有人以前尝试过这种方法,因此我们不确定这种方法的效果如何.

我觉得我缺少一些关于如何设置项目的出色解决方案.有什么建议吗?

解决方案

许多控件开发人员使用您描述的第二种方法将其Web资源捆绑在一起-将它们添加为.dll中的嵌入式资源.这样,您可以分发控件,而不必将一堆文件夹和文件复制到每个要使用它们的网站中,并确保文件夹路径都匹配,等等.您还获得了以下优势:您的资源.

但是,WebResource.axd是一个缺点.通常,您可以使用Firebug之类的工具对URL进行调试",以查看从请求中实际返回的内容,但是我同意,如果某些工具无法正常工作,可能会很痛苦.另一个缺点是,如果您有数十个资源用于一个服务器控件,尤其是如果每个资源都被多次引用(例如,在节点上有数百个小图像的树状视图),则URL可能会在最后添加大量的实际字节HTML输出.

如果您的发行/本地化需求超过了优化/调试需求,我会考虑嵌入资源.

如果没有,那么您绝对可以做#3-使用Subversion将所有内容复制到您的网站中.请查看 SVN外部对象进行设置.现在花一点时间来学习它可能会为您节省大量的时间!

I have three web application projects that share a common library of custom server controls. Sharing the code behind files is easy - they are compiled into a dll that i reference in the other projects using a project reference. But how do I handle files like JavaScript, style sheets and images? I am trying to do this "the Visual Studio way" so that it is as easy as possible to understand and debug.

The current setup is somewhat like this:

CommonControlsWebApp
+- CustomControls
+- resources
   +- images
   +- scripts
   +- stylesheets

WebApp1
+- resources*

WebApp2
+- resources*

WebApp3
+- resources*

*) Virtual directory in IIS.

The virtual directory on each web app is pointing to the resources directory in my CommonControlsWebApp. This is configured in IIS. Visual Studio is not able to understand this link, so debugging requires me to attach to the IIS-process manually.

Another solution could be to include every resource in the common dll using WebResourceAttribute. But that would turn src links into something like WebResource.axd?d=GUID when I view the source of my web pages, and I'm afraid that this will make it pretty confusing to debug.

A third solution would be to use Subversion to include the same files in all three solutions. Nobody in the team has tried this before, so we are not sure about how well this would work.

I feel that I am missing some great, obvious solution on how to setup the projects. Any suggestions?

解决方案

Many control developers bundle their webresources using the second method you describe - adding them as embedded resources in the .dll. This way, you can distribute the controls without having to copy a bunch of folders and files into every website that wants to use them, and make sure the folder paths all match, etc. You also gain the advantage of much easier localization/internationalization of your resources.

However, the WebResource.axd thing is a drawback. You can usually "debug" the URL's with something like Firebug to see what actually got returned from the request, but I agree, it can be a pain if something isn't working correctly. Another drawback is if you have dozens of resources for one server control, especially if they are referenced multiple times each (think of a treeview with hundreds of small images on the nodes) - then the URL's can add a ton of actual bytes to the final HTML output.

If your distribution/localization needs outweigh your optimization/debugging needs, I would consider embedding the resources.

If not, then you could definitely do #3 - copying everything into your website using Subversion. Check out SVN Externals for how to set it up. A little time invested into learning it now might save you tons down the road!

这篇关于如何在Visual Studio中的Web应用程序之间共享通用的Web资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆