I'm using C# in Visual Studio 2017. As shown below, I'm using the .csproj file to embed a DLL, so that the executable contains the DLL inside itself.
<ItemGroup>
<EmbeddedResource Include="example.dll">
<LogicalName>example.dll</LogicalName>
</EmbeddedResource>
</ItemGroup>
For automation purposes, I'm also building the project using MSBuild in the CLI. Thing is, I want the DLL embedding code as shown above in one of the releases, but not in the other.
I've found three ways to go about this, but the first doesn't seem possible, the second seems unwise and the third is just ugly:
Idea 1: Creating new solution configurations and then assigning conditional compilation symbols to them, followed by the usual #if()
and #endif()
commands within the code. Unfortunately, such conditional compilation does not work on the .csproj file.
Idea 2: Creating dual .sln and .csproj files for the SAME project. This way, I can edit the second .sln file to point to a second .csproj which doesn't contain the <ItemGroup>
code as shown above. I tested the idea and it appears to work, but I feel manually hand-editing such fundamental files to create seconds versions of them is risky.
Idea 3: I really don't want to do this as it breaks one of the main programming tenets - unnecessary duplication: Maintain and update two completely separate solutions/projects. Every time I adjust something in one project, I have to adjust it in the other project too. Yuck.
Is there a way to make Idea 1 work, is Idea 2 safe, and are there any alternatives?