0

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?

Andy
  • 259
  • 1
  • 4
  • 16
  • This is surprising to me. What happens in .NET 4.0 when you call `splash.Show(true)`? – John Saunders Oct 22 '13 at 20:07
  • that can be achieved with conditional compiling see this: http://stackoverflow.com/questions/2923210/c-sharp-conditional-compilation-and-framework-targets – Nickolai Nielsen Oct 22 '13 at 20:09
  • @JohnSaunders: nothing happens, its valid, whats not valid is having splash.Show(false, true); in .NET 3.5 – Andy Oct 22 '13 at 20:25
  • Thanks, you are correct, we also need the same mechanism elsewhere so conditional compiling is the best solution here. – Andy Oct 22 '13 at 20:26

1 Answers1

3

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

Community
  • 1
  • 1
Steve
  • 213,761
  • 22
  • 232
  • 286