跨项目共享母版页的最佳方式是什么
假设您有两个独立的 ASP.NET Web 应用程序项目,它们都需要使用公共母版页。
在项目之间共享 MasterPage 而无需重复代码的最佳方式是什么? 最好不必诉诸源代码控制或文件系统黑客。
Suppose you have two seperate ASP.NET Web Application projects that both need to use a common MasterPage.
What's the best way to share the MasterPage across projects without having to duplicate code? Preferably without having to resort to source control or file system hacks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
使用符号链接:
Use a symbolic link:
我不明白为什么你会想在不同的项目中使用相同的标记,如果你这样做,我不知道一个简单的方法。
然而,对于代码,显然您可以编写一个继承自
Put 的代码文件,在其中的所有母版页中放入您想要的任何逻辑。 将其构建为您出色的 dll,然后将其包含在您的项目中。
I cant see why you would want to have the same markup accross different projects, if you do, I dont know an easy way.
However with code, obviously you can write a code file which inherits from
Put in whatever logic you want in all your master pages in there. Build it as your awesome dll then just include that in your projects.
AFAIK 没有优雅的方法来完成你想要的事情.. VS 最终总是会复制它。
我认为说实话,这可能不是一个好主意..显然您想共享最低的通用代码,但是整个MasterPage?..听起来您可能会自找麻烦,因为一个微小的更改可能会对一个人产生如此大的影响或更多应用程序..
我建议将好的功能分离到组件/控件中并部署它们。
AFAIK there is no elegant way to do what you are looking to.. VS will always end up copying it.
I think to be honest it may not be a great idea.. Obviously you want to share the lowest common code, but a whole MasterPage?.. Sounds like you could be asking for trouble since one minor change could have such an impact on one or more applications..
I would suggest instead seperating out the good bits of functionality into components/controls and deploying them.
在源代码管理中保留一个主副本,并让您的源代码管理系统来处理它。
Keep a primary copy in source control, and let your source control system worry about it.
假设您可以为所有项目创建一个公共存储库(例如,源代码控制树中的公共文件夹),则可以使用相对路径将母版页添加为链接。
但是,IIRC、Visual Studio 会制作从外部路径添加的文件的本地副本。 您可能必须对解决方案/项目文件进行文本编辑才能添加链接文件。
当然,这是假设您使用“Web 应用程序”格式。 旧版 VS“网站”没有项目文件,并且依赖于网站文件夹中的所有文件。
Supposing you can create a common repository for all your projects (a common folder in your source control tree, for example), you could add the master pages as links by using relative paths.
However, IIRC, Visual Studio makes local copies of files added from external paths. You might have to text-edit the solution/project file to add the linked files.
This, of course, is assuming you use "Web Application" format. Older VS "Web Sites" do not have project files and rely on having all files within the site folder.
来自 K. Scott Allen 的 ASP.Net 母版页:提示、技巧和陷阱 文章, “共享母版页”:
From K. Scott Allen's ASP.Net Master Pages: Tips, Tricks, and Traps article, on "Sharing Master Pages":
我一直在努力完成同样的事情。 我研究了几个解决方案,但我认为使用虚拟目录可能是共享母版页的最佳方法。
您可以查看以下几个来源。
通过将其嵌入到应用程序
Dll
接近末尾的第三个项目符号文章还告诉您共享母版页的可能方法。
I have trying to accomplish the same thing. I look into a couple of solutions but I think using a virtual directory is probably the best way to share master pages.
Here are a couple sources that you can look at.
Applications by Embedding it in a
Dll
The third bullets near the end the article tells you of possible ways you can share Masterpages also.