<p>Suppose you have two seperate ASP.NET Web Application projects that both need to use a common MasterPage.</p>

<p>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.</p>

[{'answer_id': 30901, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 2, 'selected': False, 'text': '<p>Keep a primary copy in source control, and let your source control system worry about it.</p>\n'}, {'answer_id': 30904, 'author': 'Jason Bunting', 'author_id': 1790, 'author_profile': 'https://Stackoverflow.com/users/1790', 'pm_score': 0, 'selected': False, 'text': '<p>Use <a href="http://msdn.microsoft.com/en-us/library/aa365680%28VS.85%29.aspx" rel="nofollow noreferrer">a symbolic link</a>:</p>\n\n<blockquote>\n  <p>A symbolic link is a file-system object that points to another file\n  system object. The object being pointed to is called the target.\n  Symbolic links are transparent to users; the links appear as normal\n  files or directories, and can be acted upon by the user or application\n  in exactly the same manner.</p>\n</blockquote>\n'}, {'answer_id': 30907, 'author': 'Ishmaeel', 'author_id': 227, 'author_profile': 'https://Stackoverflow.com/users/227', 'pm_score': 0, 'selected': False, 'text': '<p>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. </p>\n\n<p>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.</p>\n\n<p>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.</p>\n'}, {'answer_id': 30925, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 0, 'selected': False, 'text': '<p>AFAIK there is no elegant way to do what you are looking to.. VS will always end up copying it.</p>\n\n<p>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..</p>\n\n<p>I would suggest instead seperating out the good bits of functionality into components/controls and deploying them.</p>\n'}, {'answer_id': 93978, 'author': 'Thomas Wagner', 'author_id': 13997, 'author_profile': 'https://Stackoverflow.com/users/13997', 'pm_score': 2, 'selected': False, 'text': '<p>From K. Scott Allen\'s <a href="https://odetocode.com/Articles/450.aspx" rel="nofollow noreferrer">ASP.Net Master Pages: Tips, Tricks, and Traps</a> article, on "Sharing Master Pages":</p>\n\n<blockquote>\n  <p>The first alternative is to copy shared master page files into a\n  single location on an IIS web server. Each application can then create\n  a virtual directory as a subdirectory and point the virtual directory\n  to the real directory of master pages. The applications can then set\n  the MasterPageFile property of a page to the name of the virtual\n  directory, plus the name of the master page file. When we drop an\n  updated master page file into the real directory, the new master page\n  will appear in all the applications immediately.</p>\n  \n  <p>A second approach is to use a version control system to share a set of\n  master page files across multiple projects. Most source control /\n  version control systems support some level of “share” functionality,\n  where a file or folder can appear in more than one project. When a\n  developer checks in an updated master page file, the other projects\n  will see the change immediately (although this behavior is generally\n  configurable). In production and test, each application would need to\n  be redeployed for the update master page to appear.</p>\n  \n  <p>Finally, the VirtualPathProvider in ASP.NET 2.0 can serve files that\n  do not exist on the file system. With the VirtualPathProvider, a set\n  of master pages could live in database tables that all applications\n  use. For an excellent article on the VirutalPathProvider, see “<a href="https://msdn.microsoft.com/en-us/library/aa479502.aspx" rel="nofollow noreferrer">Virtualizing Access to Content: Serving Your Web Site from a ZIP File</a>”.</p>\n</blockquote>\n'}, {'answer_id': 94027, 'author': 'Chris James', 'author_id': 3193, 'author_profile': 'https://Stackoverflow.com/users/3193', 'pm_score': 0, 'selected': False, 'text': '<p>I cant see why you would want to have the same markup accross different projects, if you do, I dont know an easy way.</p>\n\n<p>However with code, obviously you can write a code file which inherits from </p>\n\n<pre><code>System.Web.UI.MasterPage\n</code></pre>\n\n<p>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.</p>\n'}, {'answer_id': 375755, 'author': 'JkenshinN', 'author_id': 40350, 'author_profile': 'https://Stackoverflow.com/users/40350', 'pm_score': 5, 'selected': True, 'text': '<p>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.  </p>\n\n<p>Here are a couple sources that you can look at. </p>\n\n<ul>\n<li><a href="https://blogs.msdn.microsoft.com/shahpiyush/2007/03/09/sharing-master-pages-amongst-applications-by-embedding-it-in-a-dll/" rel="nofollow noreferrer">Sharing Master Pages amongst\nApplications by Embedding it in a\nDll</a></li>\n<li><a href="https://msdn.microsoft.com/en-us/library/aa992039.aspx" rel="nofollow noreferrer">Sharing Master Pages in Visual Studio</a></li>\n<li><a href="http://www.odetocode.com/articles/450.aspx" rel="nofollow noreferrer">ASP.Net 2.0 - Master Pages: Tips, Tricks, and Traps </a></li>\n</ul>\n\n<p>The third bullets near the end the article tells you of possible ways you can share Masterpages also.</p>\n'}]
['https://Stackoverflow.com/questions/30884', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/247/']