What is the best way to share MasterPages across projects

前端 未结 7 1034
别那么骄傲
别那么骄傲 2020-12-09 09:10

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 project

相关标签:
7条回答
  • 2020-12-09 09:11

    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

    System.Web.UI.MasterPage
    

    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.

    0 讨论(0)
  • 2020-12-09 09:13

    Keep a primary copy in source control, and let your source control system worry about it.

    0 讨论(0)
  • 2020-12-09 09:16

    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.

    0 讨论(0)
  • 2020-12-09 09:26

    Use a symbolic link:

    A symbolic link is a file-system object that points to another file system object. The object being pointed to is called the target. Symbolic links are transparent to users; the links appear as normal files or directories, and can be acted upon by the user or application in exactly the same manner.

    0 讨论(0)
  • 2020-12-09 09:32

    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.

    0 讨论(0)
  • 2020-12-09 09:34

    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.

    • Sharing Master Pages amongst Applications by Embedding it in a Dll
    • Sharing Master Pages in Visual Studio
    • ASP.Net 2.0 - Master Pages: Tips, Tricks, and Traps

    The third bullets near the end the article tells you of possible ways you can share Masterpages also.

    0 讨论(0)
提交回复
热议问题