Only embed some resources in certain build configurations?

P

P Chase

I have some resources in my C# Visual Studio 2005 project that are
involved with self-test. Ideally, they shouldn't be in a released
product.

These resources are embedded by virtue of having their Build Action
property set to Embedded Resource.

Is there any way to add conditions to when they are embedded? For
instance, can I create a build configuration under which they are not
embedded?
 
M

Marc Gravell

Yes; not via the IDE, but you can edit the csproj directly (right click,
unload, edit) - add an attribute to the EmbeddedResource element:

<EmbeddedResource Include="Foo.txt"
Condition="'$(Configuration)'=='Debug'" />

(or whichever configuration you want to include it in)

Marc
 
P

P Chase

Yes; not via the IDE, but you can edit the csproj directly (right click,
unload, edit) - add an attribute to the EmbeddedResource element:

<EmbeddedResource Include="Foo.txt"
Condition="'$(Configuration)'=='Debug'" />

(or whichever configuration you want to include it in)

Marc

Thanks. That works fine. Is it likely that Visual Studio will
overwrite my hand-edited addition in the future, or is it smart enough
to persist it, once added?
 
M

Marc Gravell

I haven't seen any oddities... you might want to keep an eye on it when
changing from 2005 to 2008, for example, but in general it seems to know
enough to leave it alone...

But if you see any problems...

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top