Project reference work-around .net 4.5 and .net 3.

2019-01-19 07:32发布

问题:

In continue for this thread:
Mixing .NET 3.5 with 4/4.5 assemblies in the same solution/project

I found a workaround:
http://social.msdn.microsoft.com/Forums/en-US/clr/thread/36b1a209-55d5-4323-91dc-0919ba2e1d03/

What it basically do, get my solution compile and determine each project under what CLR to run.
Does anyone see disadvantage to this ?
It builds the projects, on my 3rd party api that must run on .net 3.5, i explicity write on its App.config to run with CLR 2.0 and not 4.0

 <startup>
 <supportedRuntime version="v2.0.50727"/>
 <!--<supportedRuntime version="v4.0"/>-->
 </startup>

EDIT:
My main application is using .net 4.5 and C# 5 features. My 3rd party API is running on a child process (i start from main) and that process will connect to API that must be on 3.5 and CLR2. So i explicity define there to run as CLR2..

回答1:

Your configuration file will load .NET 2.0 runtime and it would fail at some point loading .NET4.5 components. You really want your app to run in .NET4.5 runtime and be able to load 3.5 components. You should try following config file.

<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
    </startup>
</configuration>