Reputation:
How can I choose which resources to compile depending of the compile constants used? So, if VAR1=0 then I wouldn't add RESOURCE_A to my final assembly.
I searched around, but didn't find any info regarding this... I guess I'm using the wrong keywords, since I doubt nobody else had this problem/doubt ever before.
Also, I use both VS2005 and 2008 at my job, mainly VB, although I haven't got any problem using C# either.
Upvotes: 1
Views: 273
Reputation: 11750
You could accomplish this using the MSBuild <Choose> element:
<Choose>
<When Condition=" '$(Configuration)'=='Debug' ">
<ItemGroup>
<EmbeddedResource Include="debug_resource.txt" />
</ItemGroup>
</When>
<When Condition=" '$(Configuration)'=='retail' ">
<ItemGroup>
<EmbeddedResource Include="retail_resource.txt" />
</ItemGroup>
</When>
</Choose>
... of course, you could use something other than the $(Configuration) variable. You can check existence of a file/folder, use the output of another task, or use a different variable altogether.
Upvotes: 1
Reputation: 124776
Compile constants only affect code. You could add both resources to the assembly, and retrieve the appropriate one depending on the compile constant.
There are of course other ways to achieve this - e.g. copying the appropriate resource in a pre-build event based on some criterion you define.
Upvotes: 0