VS2010 Projects with Common Files

Go To StackoverFlow.com

1

I have a vb.net project that has 2 exe's that get built as well as the installer. The two exe's share a bunch of common files. I do not want to have two copies of the common files or mess around with having build events that copy things around (if possible).

My method was to create two projects in the same folder and have them point to the files they needed. This appeared to work until I tried to compile both apps at which point I get an error in a file called Application.Designer.vb. It seems that project files create this file in their folder and when I have two solutions in the same folder they conflict.

So my next effort was to create the second project in it's own folder and just add the items as needed. The problem here is that VS2010 doesn't hold a link to a file in a different folder it copies the file to the new project folder.

What is the vs2010 way to get this done?

2012-04-04 00:18
by Hucker


3

You were almost there when you created your second project. Rather than adding the files to the second project, you need to link them.

When you add them, VS copies the source file to the current project's directory.

When you link a file, it leaves it in its current location and just adds a reference to the file to your project. This means that you are operating with a single source file instead of multiple copies.

To link a file, choose Add Existing Item... menu item from the Project menu, select the file(s) that you want to link, and then click the dropdown arrow next to the Add button on the file dialog and select Add As Link.

We have class files that are shared this way among a half-dozen projects, including Win Forms, Silverlight, ASP.Net, Services, and PocketPC.

2012-04-04 00:57
by competent_tech
This is exactly what I was looking for. I had no idea the add button could be turned into a link button on the screen. It took me just a few minutes to get everything working nicely. Thanks - Hucker 2012-04-05 06:33
How about a folder ? I mean I got tons of sharing resource like image - maxisam 2012-08-22 15:29
@maxisam: what I generally do in cases like this is actually add all of the resources into a common DLL that is then shared among all applications that require it - competent_tech 2012-08-22 16:01


3

The easiest solution would be to shove all the common stuff into a common project, and simply reference that project from your other two solutions.

  • Solution A:
    • Project A
    • Project C
  • Solution B:
    • Project B
    • Project C

Just my recommendation anyway.

2012-04-04 00:24
by Josh
I guess I don't see how this can help me unless you are saying that I should build the common files into a DLL project and include that dll into each project. I think that is possible but it seems really messy compared to what appears to be simple thing ... having files in different folders. If that is the best solution then I need to rethink what I'm doing. Thanks - Hucker 2012-04-04 00:48
@Hucker - basically yes. You can technically share files by making them "linked" files, but that too can be messy. In my opinion once you start having more than a couple shared resources you need a DLL project. It's not necessarily messy either... especially if it means less work than what you are currently doing ; - Josh 2012-04-04 01:10
Ads