What is the best way to share MasterPages across projects
Asked Answered
L

7

24

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.

Locket answered 27/8, 2008 at 18:57 Comment(0)
S
11

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.

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

Staunch answered 17/12, 2008 at 19:36 Comment(0)
T
4

From K. Scott Allen's ASP.Net Master Pages: Tips, Tricks, and Traps article, on "Sharing Master Pages":

The first alternative is to copy shared master page files into a single location on an IIS web server. Each application can then create a virtual directory as a subdirectory and point the virtual directory to the real directory of master pages. The applications can then set the MasterPageFile property of a page to the name of the virtual directory, plus the name of the master page file. When we drop an updated master page file into the real directory, the new master page will appear in all the applications immediately.

A second approach is to use a version control system to share a set of master page files across multiple projects. Most source control / version control systems support some level of “share” functionality, where a file or folder can appear in more than one project. When a developer checks in an updated master page file, the other projects will see the change immediately (although this behavior is generally configurable). In production and test, each application would need to be redeployed for the update master page to appear.

Finally, the VirtualPathProvider in ASP.NET 2.0 can serve files that do not exist on the file system. With the VirtualPathProvider, a set of master pages could live in database tables that all applications use. For an excellent article on the VirutalPathProvider, see “Virtualizing Access to Content: Serving Your Web Site from a ZIP File”.

Thorndike answered 18/9, 2008 at 16:7 Comment(0)
S
2

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

Silveira answered 27/8, 2008 at 19:0 Comment(0)
S
0

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.

Sorbose answered 27/8, 2008 at 19:0 Comment(0)
B
0

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.

Baculiform answered 27/8, 2008 at 19:2 Comment(0)
E
0

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.

Elephus answered 27/8, 2008 at 19:10 Comment(0)
M
0

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.

Mocha answered 18/9, 2008 at 16:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.