You should probably use MSBuild features to implement this.
Edit the csproj file (in Visual Studio, right click the project and unload it. then right click and edit)
Scroll to the bottom and you should find this line.
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Immediately after that line, add these lines.
<ItemGroup>
<LinkedItem Include="@(None)" Condition="'%Link' != ''" />
</ItemGroup>
<Target Name="CopyLinkedFiles" BeforeTargets="Build" Inputs="@(LinkedItem)" Outputs="@(LinkedItem->'%(Filename)%(Extension)')">
<Copy SourceFiles="@(LinkedItem)" DestinationFolder="$(MSBuildProjectDirectory)" />
</Target>
Now every time you build, right before the build action occurs, MSBuild will copy all linked files.
Explanation
ItemGroup
contains my "array" named "LinkedItem". I generate this array by adding only the "None" items that contain a link property.
Target
is an MSBuild concept. You can think of it as a particular phase of the build. I named this phase "CopyLinkedFiles" but you can name it anything.
BeforeTargets
is a directive that tells MSBuild to run the action before the specified phase. Here, I have chosen to run "CopyLinkedFiles" before the "Build" phase.
Inputs
is an optimization parameter. It is used to speed up building by skipping the copy if not necessary. You can ignore this parameter if you don't care. MSBuild compares the Inputs
to the expected Outputs
timestamp to see if it needs to execute.
Copy
is an MSBuild task that accepts a file to copy and outputs to the specified folder.
Reducing Redundancy
You could paste this into every .csproj file, or you could put it in a central .proj and embed that into the csproj files. Sadly, no matter what you do, you will have to edit every .csproj at least 1 time. :(
Create a file in the Common project call WhateverNameYouLike.proj
Put these contents into the file.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- paste the previously shown code here -->
<!-- you can save yourself some hassle by linking the config file here, but if you really enjoy adding the file as a link to every project, you can skip this line -->
<None Include="..\Common\Shared.config">
<Link>Shared.config</Link>
</None>
</Project>
Now the annoying part:
In every .csproj, you will have to add a line like
<Import Project="..\Common\WhateverNameYouLike.proj" />
probably at the end just before the </Project>
closing tag.