views:

111

answers:

2

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.

A: 

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.

Joe
So, compile constants cannot be defined for resources on .NET?Also, Adding all the resources is not always wanted because:A) They add size overhead to the final assemblies.B) There may be resources you don't want to compile into the assemblies of some versions of the software
+1  A: 

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.

Mark