In C# Project files as written by Visual Studio or SharpDevelop, files that are not located in the folder hierarchy of a project can be included with a <Link>
element.1
My directory structure looks like this:
[SolutionDirectory]
|- [MyProject]
| |- TestProj.csproj
|- [File]
| |- somefile.txt
|- TestProj.sln
Hence, in TestProj.csproj, I can add the following:
<ItemGroup>
<EmbeddedResource Include="..\File\somefile.txt">
<LogicalName>MyResource</LogicalName>
<Link>somefile.txt</Link>
</EmbeddedResource>
</ItemGroup>
This works flawlessly, and somefile.txt is embedded as a resource. The project tree is shown as follows by SharpDevelop 4.4:
However, to make things tidier, I would like to organize files like somefile.txt in a folder hierarchy within TestProj.csproj. I have tried the following:
Just adapting the <Link>
:
<ItemGroup>
<EmbeddedResource Include="..\File\somefile.txt">
<LogicalName>MyResource</LogicalName>
<Link>File\somefile.txt</Link>
</EmbeddedResource>
</ItemGroup>
Declaring a folder of the desired name:
<ItemGroup>
<EmbeddedResource Include="..\File\somefile.txt">
<LogicalName>MyResource</LogicalName>
<Link>File\somefile.txt</Link>
</EmbeddedResource>
<Folder Include="File" />
</ItemGroup>
Declaring the actual folder as a link:
<ItemGroup>
<EmbeddedResource Include="..\File\somefile.txt">
<LogicalName>MyResource</LogicalName>
<Link>File\somefile.txt</Link>
</EmbeddedResource>
<Folder Include="..\File">
<Link>File</Link>
</Folder>
</ItemGroup>
All of these yield the same result: The folder structure in the project is shown as desired, however, the File folder is marked with a yellow exclamation mark warning sign, implying that something is not quite all right:
The only way I have found to make this warning symbol go away is to actually create an additional File folder in the project directory:
[SolutionDirectory]
|- [MyProject]
| |- [File]
| |- TestProj.csproj
|- [File]
| |- somefile.txt
|- TestProj.sln
As gets visible here, this additional File folder would remain empty, and empty directories is only possible with workarounds for version control systems such as Git. (Possibly, the same restriction applies to some archive formats.)
Therefore, I am still trying to find a better solution: How can I link to files outside of the folder structure of my project and sort them into an otherwise empty folder hierarchy within my project?
Unfortunately, the MSBuild Schema Reference on MSDN does not even mention the <Folder>
element, so I failed to find out anything about the issue via the docs.
1: In general, this serves for including files in several projects. In my particular case, I am working on a project that needs to reference a class library in the same solution, but it also needs to include the entire source code (including the project file etc.) of that class library as an embedded resource.