Reputation: 259
I have the same file that i want to compile in a .net 3.5 project and a 4.0 project.
The api has changed the between the versions of .net, for example I have the following line of code which shows a splash screen on startup:
.net 4.0: splash.Show(false, true);
.net 3.5: splash.Show(true);
How can i use the same source file in both projects?
Upvotes: 0
Views: 118
Reputation: 216303
Create a a conditional compilation symbol in the properties page of your project that encloses the problematic file, for example
NET40
then, in code write
#if NET40
splash.Show(false, true);
#else
splash.Show(true);
#endif
You could also create two different Configuration Settings with the Configuration Manager
.
In the first one you don't have the NET40 defined and you could call it CompileFor35
while in the other one you define the compilation symbol and call it CompileFor40
.
At this point, to switch from one version to the other one, you could simply recall the appropriate configuration setting from the menu BUILD->Configuration Manager
You could read about the steps required in a bit more detail in this answer
Upvotes: 3