Visual Studio Related File Directory Structure

I have two versions of the project. One for Silverlight and one for .NET. The SL project has the vast majority of the code base in it. I want to globally add all the files from the SL project to the .NET version as linked files. I managed to do this successfully in the csproj file for the .NET version:

<Compile Include="..\MyProj.Common.SL\**\*.cs" Exclude="..\MyProj.Common.SL\Properties\**"> 

Unfortunately, this adds all the files right to the root of my project ... so that I get a long unreadable list of related files in a .NET project. I really really don't want to maintain the entire structure of duplicate directories manually and handle directory name changes and file name changes and something else.

So, is there a way for Visual Studio to maintain the directory structure when adding related files under the template above? Or at least a way to make it merge all related files together into a directory in a .NET project, such as MyProj.Common.SL.Links?

The closest I came is to set <Visible>false</Visible> under the <Compile> , which effectively removes a long unreadable list from 300+ files ... but, unfortunately, this forces Resharper, which no longer sees these the files are valid and this is crazy for all projects that reference a .NET project. If I could find a way to get Resharper not to get confused, that would be an acceptable solution too ...

Any suggestions?

Thanks.

+2
source share
2 answers

I guess I found a way to make this work:

 <Compile Include="..\MyProj.Common.SL\**\*.cs" Exclude="..\MyProj.Common.SL\Properties\**"> <Link>MyProj.Common.SL.LinkedFiles\MyProj.Common.SL.LinkedFiles</Link> </Compile> 

It will create the MyProj.Common.SL.LinkedFiles folder and group all related files in this folder.

+4
source

I think I would do this:

  • Copy the existing <Compile> project objects that supposedly have, for example, Include="foo.cs" and Include="Folder\bar.cs"
  • Paste them into a new project
  • Find and replace <Compile Include="(.*?)" /> <Compile Include="..\Other\$1" ><Link>$1</Link></Compile>

I don’t know if I got the regular expression search correctly and replaced the syntax, but the fact is that you already have a good project, you should be able to cut, paste, re-expose, replace it to get the same set of files, only Links from another folder and with the same directory structure.

You still have two .csprojs to support at this point, but this is also easily fixed. Now take this new list of compilation elements and put it in a file with a name, for example. "Common.csproj", which simply contains a group of properties with these compiled elements, and then has both projects <Import Include="..\Common.csproj" /> and does not include any Compile elements.

Basically, a little manual labor for refactoring a .csproj file for sharing once, and then I think that you will be installed. I'm not sure if this is the easiest way to unlock you, but I think it looks like what you might need for a “perfect” structure.

0
source

All Articles