简体   繁体   English

.net3.5和.net4.0项目之间的共享源文件

[英]Shared source file between .net3.5 and .net4.0 projects

I have the same file that i want to compile in a .net 3.5 project and a 4.0 project. 我有要在.net 3.5项目和4.0项目中编译的相同文件。

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: api已更改.net版本之间的api,例如,我有以下代码行,显示了启动时的启动画面:

.net 4.0: splash.Show(false, true);
.net 3.5: splash.Show(true);

How can i use the same source file in both projects? 如何在两个项目中使用相同的源文件?

Create aa 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 . 您还可以使用Configuration Manager创建两个不同的Configuration Settings。 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 . 在第一个中,您没有定义NET40,可以将其CompileFor35而在另一个中,您可以定义编译符号并命名为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 此时,要从一种版本切换到另一种版本,您只需从菜单BUILD->Configuration Manager调用适当的配置设置即可。

You could read about the steps required in a bit more detail in this answer 您可以在此答案中更详细地了解所需的步骤

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM