Automatically add links to class source files under a specified directory of an another project in V

Posted by Binary255 on Stack Overflow See other posts from Stack Overflow or by Binary255
Published on 2010-05-03T19:14:09Z Indexed on 2010/05/03 19:18 UTC
Read the original article Hit count: 324

Filed under:
|

I want to share some class source files between two projects in Visual Studio 2008. I can't create a project for the common parts and reference it (see my comment if you are curious to why).

I've managed to share some source files, but it could be a lot more neat. I've created a test solution called Commonality.

The Solution Explorer of the Commonality solution which contains project One and Two:

alt text

What I like:

  • All class files under the Common folder of project One are automatically added to project Two by linking. It's mostly the same as if I would have chosen Add / Existing Item... : Add As Link on each new class source file.
  • It's clear that these files have been linked in. The shortcut arrow symbol is marking each file icon.

What I do not like:

  • The file and folder tree structure under Common of project One isn't included. It's all flat.
  • The linked source files are shown under the project root of project Two. It would look much less cluttered if they were located under Common like in project One.

The file tree structure of the Commonality solution which contains project One and Two:

$ tree /F /A

Folder PATH listing for volume Cystem
Volume serial number is 0713370 1337:F6A4
C:.
|   Commonality.sln
|
+---One
|   |   One.cs
|   |   One.csproj
|   |
|   +---bin
|   |   \---Debug
|   |           One.vshost.exe
|   |           One.vshost.exe.manifest
|   |
|   +---Common
|   |   |   Common.cs
|   |   |   CommonTwo.cs
|   |   |
|   |   \---SubCommon
|   |           CommonThree.cs
|   |
|   +---obj
|   |   \---Debug
|   |       +---Refactor
|   |       \---TempPE
|   \---Properties
|           AssemblyInfo.cs
|
\---Two
    |   Two.cs
    |   Two.csproj
    |   Two.csproj.user
    |   Two.csproj~
    |
    +---bin
    |   \---Debug
    +---obj
    |   \---Debug
    |       +---Refactor
    |       \---TempPE
    \---Properties
            AssemblyInfo.cs

And the relevant part of project Two's project file Two.csproj:

<ItemGroup>
  <Compile Include="..\One\Common\**\*.cs">
  </Compile>
  <Compile Include="Two.cs" />
  <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

How do I address what I do not like, while keeping what I like?

© Stack Overflow or respective owner

Related posts about visual-studio-2008

Related posts about msbuild