如何创建一个共享的ASP.Net MVC项目(Web框架),以便它可以在其他多个MVC项目中重用? [英] How to create a shared ASP.Net MVC project (web framework) so that it can be re-used in other multiple MVC projects ?

查看:48
本文介绍了如何创建一个共享的ASP.Net MVC项目(Web框架),以便它可以在其他多个MVC项目中重用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要构建多个mvc Web应用程序。我有一些框架组件可以在这些应用程序中重用。即使我有一个UI框架,它可以动态呈现UI。有没有办法将这个Web项目作为共享项目,并且可以将它们的引用添加到不同的应用程序中,这样它们也可以支持那些开箱即用的框架组件?

I need to build multiple mvc web applications. I have some framework components which can be re-used in those applications. Even I have a framework for the UI, which can render the UI dynamically. Is there a way to make this web project as a shared one and their reference can be added to different applications so that they will also have the support for those framework components out of the box ?

推荐答案

正常创建MVC项目,然后将共享项目作为类库添加到同一解决方案中,并将项目引用添加到MVC项目的共享项目中。对于其他站点,也为这些解决方案添加相同的共享库。这样,如果您需要对共享库进行更改,您可以立即进行更改,每次打开不同的解决方案时,您也会自动获得共享项目的最新版本。显然,您必须谨慎对待更改,即更改可能会破坏其他项目的共享库。由于此方法将为您提供项目的不同版本的dll,您只是真正共享源代码,因此每个项目都有自己的程序集副本。要实际共享程序集本身,您需要使用GAC,但这样做会比实际更麻烦,并且会给您带来更大的更新破坏其他项目的风险。
Create your MVC project as normal then add your shared project as a class library to the same solution and add a Project Reference to the shared project from your MVC project. For other sites add the same shared library to those solutions also. That way if you need to make changes to the shared library you can make them right away, and every time you open a different solution you'll automatically get the latest version of the shared project too. Obviously you have to be wary of breaking changes though, ie changes to the shared library that might break other projects. As this method will give you different versions of the dll with the project you're only sharing the source code really, each project will have its own copy of the assembly. To actually share the assembly itself you'll need to use the GAC but that'll be more hassle than is worth and gives you a far greater risk of updates breaking other projects.


编译它作为DLL,只需将它包含在项目引用中,无论你需要它。
Compile it as DLL and simply include it in project references wherever you need it.


这篇关于如何创建一个共享的ASP.Net MVC项目(Web框架),以便它可以在其他多个MVC项目中重用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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