views:

652

answers:

7

Hello,

First shot at throwing a question on these boards so hopefully I can get some help, here goes:

I am working to start up the .NET practice at my client. We have 5 small scale .NET applications in place currently with a few them of them live into production. They're mostly small reporting pieces with some data entry/business logic functionality. Each of these applications is currently using the identical master pages.

What I mean is that there is a copy of the same master page in each application. They are all basic website->WCF->BL->DB tiered applications. So I have 4 copies of the same master page that I have to change when I make a change to it.

The client DOES NOT want to consolidate all of these into a single solution. They like the separation of applications across sites. I just don't want to continue dealing with the hassle of multiple updates for common elements (which there will be many more of across these applications).

The code is all stored in team foundation server. We also do NOT want to compile the master page into a .dll and deploy it.

Can anyone please make some suggestions as to how I can maintain a single copy of these common files (master, .css, etc) across my multiple applications.

thanks in advance

A: 

The client DOES NOT want to consolidate all of these into a single solution. They like the separation of applications across sites. I just dont want to continue dealing with the hassle of multiple updates for common elements (which there will be many more of across these applications).

The code is all stored in team foundation server. We also do NOT want to compile the master page into a dll and deploy it.

You eliminated the only two real options there. What all is in the master page? Would it be possible to extract the HTML UI elements to a single template or series of template HTML files and import those dynamically into the master page? You could then relocate the common HTML to an arbitrary URL and have the master page for each application pull it in dynamically.

Edit: I lied. You could also use a VirtualPathProvider like Sharepoint does to store the master page in a database or some other directory, but beware that VirtualPathProviders do not work in MediumTrust environments.

See:
http://msdn.microsoft.com/en-us/library/system.web.hosting.virtualpathprovider.aspx

Chris
I ended up going with this route. I created a virtual path provider and built my master page into a DLL and this is working. Now I have a massive problem though in that a Content page whos master page is late bound through the codebehind throws validation/formatting hissy fits because it thinks its should be a stand along page. my CNTRL + K, CNTRL + D has broken on every page where I'm now sharing my master page. This is extremely frustring for me and the team.
chrisjlong
+1  A: 

You might want to look at Sharing Master Pages in Visual Studio.

If that is no help then you could try using Build Events in Visual Studio. I would pick one of the projects to be my "Main Project" and only edit the master page from that project. When you build the project it would run a command that would copy that master page(if it had changed) to your set locations.

cgreeno
A: 

Awesome. I will give all of this a try.

Please feel free to throw anymore suggestions out there. I will post an update if I can get one of these methods working.

Thanks!

chrisjlong
Use comments to say thanks to someone, then mark the checkbox to call it an answer. Don't create a new 'answer' to say thanks.
Mufasa
A: 

If you are using Web Applications (compiled into a dll) rather than Web Sites you can do the following:

Right click on the folder you want to store the master page in

Select "Add Existing Item..."

Browse to the master page on the file system, and select both the .master and the .master.cs files.

Then, rather than clicking on the "Add" button, click on the little down arrow to the right of Add, this will bring up a little menu with the options: "Add" and "Add As Link"

Select "Add As Link" this will reference the file in your project, while leaving it in the original location in your dev environment - this allows you to edit it in either application, while keeping it up to date in the other applications.

Obviously if you edit the code behind, you'll need to re-compile the other projects before you deploy the changes to those sites.

This isn't available in web site projects as they rely on the file structure to work out what is in the project.

Zhaph - Ben Duguid
A: 

EDIT: Missed the css part. Obviously you won't be able to serve those files, so this should only work for the master page.

Don't know your scenario, so

IF you can control the DNS / virtual directories to the applications you could use a format like this:

c:\inetpub\wwwroot\Application1
c:\inetpub\wwwroot\Application2
c:\inetpub\wwwroot\Application3
c:\inetpub\wwwroot\Application4
c:\inetpub\wwwroot\Application5
and have your Master page at c:\inetpub\wwwroot\master.Master,
c:\inetpub\wwwroot\master.Master.cs,
c:\inetpub\wwwroot\master.Master.cs.designer

Then you could reference the single copy of the master page from /../master.Master. I gave this a quick shot with a precompiled master page to make sure I could reach back beyond my root. You might have to give it a shot to see.

benjynito
A: 

We use our source control to create links to the shared files in all the places that we need it. So if you edit in one place, you just need to do a get latest and it will appear in the other places you have linked it.

Andrew Barrett
A: 

I ended up going with the VPP route. I created a virtual path provider and built my master page into a DLL and this is working. Now I have a massive problem though in that a Content page whos master page is late bound through the codebehind throws validation/formatting hissy fits because it thinks its should be a stand along page. my CNTRL + K, CNTRL + D has broken on every page where I'm now sharing my master page. This is extremely frustring for me and the team

chrisjlong