Sharing Files Between ASP.NET Projects

485 words.

These rambling thoughts document my search for a way to share files between Visual Studio web projects.

I’ve got a web solution that really should be three entirely separate web solutions, but many of the pages are exactly the same between them. I could copy the shared files to the three projects, but for obvious reasons that’s not a desirable solution… I just want to maintain one copy of the shared files. How the heck do you do that in Visual Studio?

Turning to Google, I see there is this nifty feature for adding existing items as links. Cool! That will solve my problem nicely!

Um, except it doesn’t work for web projects:

“Visual Basic Web projects, Visual C# Web projects, and other similar projects do not support links to items.”

Back to the drawing board. Surely I’m not the first one to ever think of sharing a common page among multiple web projects?

Some Google hits referred to sharing the files in SourceSafe. This is a personal choice, but I don’t like doing that because it feels dirty. It still looks like multiple files in multiple directories. Plus, I worked on a project once where tons of files were shared like that and SourceSafe was really slow propagating changes. If possible, I just want one file in one directory, both in source control and on my hard drive.

Finally I found an MSDN KB article describing how to share an ASP.NET control between two or more projects. Basically Microsoft is saying that you should put the shared controls — I assume it would work for pages, too - into multiple virtual sub-directories all pointing to the same physical location. I’m not wild about this solution because in my situation I prefer not to rely on IIS tricks, but it’s definitely the best option so far.

Of course, there is always the option of building the projects outside of Visual Studio with a tool like NAnt, where you can build projects from any files scattered all over creation. If it were just me I might consider that route but, again, in my situation it’s generally better to keep things simple. (That is my coy way of saying that nobody else would know what the heck NAnt is or how to build anything with it.) Even worse, I’d still have to make copies of the shared files to do any debugging inside Visual Studio.

Hrm, that gives me an idea. Maybe a combination of those last two methods would work:  Use the virtual directories for local debugging, but create a NAnt project to build the deployable production site. It’s so crazy it just might work!

P.S. It was too crazy and didn’t work. :) Actually I can’t say that for sure because I gave up and left the three sub-apps in a single web solution. The difficulty in separating them outweighed the advantage of separating them.

Related

This page is a static archival copy of what was originally a WordPress post. It was converted from HTML to Markdown format before being built by Hugo. There may be formatting problems that I haven't addressed yet. There may be problems with missing or mangled images that I haven't fixed yet. There may have been comments on the original post, which I have archived, but I haven't quite worked out how to show them on the new site.

Sorry, new comments are disabled on older posts. This helps reduce spam. Active commenting almost always occurs within a day or two of new posts.