Reputation: 2157
I have written a Visual Studio C# project and I have the need to create two executable, one for a "lite version" and one for a "full version" of the same project.
The "lite version" will be a stripped down version of the full one so I want to share everything (code, resources, etc.) and, if possible, use compiling directive to isolate code blocks.
Can you tell me a way to do this in a clean way?
Upvotes: 1
Views: 355
Reputation: 101162
You can create a new Conditional compilation symbol in your project (say FULLVERSION
). Create a new Solution configuration (say ReleaseFullversion) using the Configuration Manager, and in this configuration, define the FULLVERSION
constant.
You can then wrap code block with
#if FULLVERSION
...
#end if
or use the Conditional atrribute
[Conditional("FULLVERSION")]
void MyMethod()
{...}
to create a stripped down version your application.
Code within these #if
-blocks and these Conditional
attributes won't be compiled into your assembly if the FULLVERSION
constant is not set (the Conditional
attributes just removes the call to that code block, actually).
Then you would either build a lite version of your solution, or a Fullversion, which includes the full code.
Upvotes: 2
Reputation: 7666
To do this all within visual studio, you require something of a strange ritual that is a little non-obvious to anyone simply looking at your project, so it is important to figure out a training regimen to make sure everyone knows what is going on.
First, right-click on the solution you have and go to properties. Click on "Configuration Manager" and make a new configuration. Call it "Lite" or whatever pleases you.
You may then right-click each project in your solution to set the conditional compilation properties you need. You may then use Conditional Compilation Symbols to isolate what is 'full' and what is 'lite'.
After this has been fully configured, it will appear in the top of visual studio's UI - where you normally see Debug and Release, you will now see Lite or whatever you just configured.
Upvotes: 1
Reputation: 62265
You can use Visual Studio Post Build events, where from the batch call DEVENV.EXE
to your project with some special parameter that makes it compile in a different way.
Using Devenv at the command prompt to build projects
Upvotes: 1