2009-05-22 69 views
7

可以说我有一个旧的应用程序将尝试加载外部程序集。如何运行CLR 2应用程序作为CLR 4应用程序

  • 旧的应用程序被编译为CLR 2
  • 新组件被编译为CLR 4

我想能够运行内部CLR 4.我记得旧的应用程序有一些涉及xml manifest magic

如何创建该清单xml文件来告诉oldapplication.exe应该在CLR 4下运行?

我发现了一些建议,但它们似乎不适合我。

oldapplication.exe.config:

<?xml version ="1.0"?> 
<configuration> 
<startup> 
     <!--set the appropriate .net version--> 
     <requiredRuntime version="4.0.0.0"/> 
</startup> 
</configuration> 

同时给予再出手,我发现这个文件作为我的TEMPL吃:

C:\ WINDOWS \ Microsoft.NET \框架\ v4.0.20506 \ Aspnet_regsql.exe.config

<?xml version ="1.0"?> 
<configuration> 
    <startup> 
     <supportedRuntime version="v4.0.20506"/> 
     <requiredRuntime version="v4.0.20506" safemode="true"/> 
    </startup> 
</configuration> 

我也更新了代码报告当前CLR:

Console.WriteLine(typeof(object).Assembly.ImageRuntimeVersion); 

它现在有效!

+1

+1。也只是要问这个问题,因为我真的需要.NET 4的64位JIT来支持正确的尾部呼叫。 – leppie 2011-05-12 10:42:12

回答

7

您需要提供正确的版本号。请注意,这是测试版本1,它将改变直到RTM落户之一:

<configuration> 
<startup> 
     <supportRuntime version="4.0.20506"/> 
</startup> 
</configuration> 
1

我相信你想使用supportedRuntime,而不是requiredRuntime。

“<supportedDuntime>元素应该由使用版本1.1或更高版本的运行时构建的所有应用程序使用。” (http://msdn.microsoft.com/en-us/library/a5dzwzc9.aspx)。确保版本字符串与所需版本的“安装文件夹名称”完全匹配。

1

为乡亲在2013+

配置文件吉斯特发现通过谷歌这个网页
https://gist.github.com/1223509

博客文章
http://yzorgsoft.blogspot.com/2011/09/greenshot-on-windows-8-net-45.html

<?xml version ="1.0"?> 
<configuration> 
    <startup useLegacyV2RuntimeActivationPolicy="true"> 
    <supportedRuntime version="v4.0.30319" /> 
    <requiredRuntime version="v4.0.30319" safemode="true"/> 
    </startup> 
    <runtime> 
    <relativeBindForResources enabled="true" /> 
    <UseSmallInternalThreadStacks enabled="true" /> 
    <DisableMSIPeek enabled="true"/> 
    </runtime> 
</configuration> 

该配置文件是从Visual Studio 2012中提取的,因此它具有一些额外的COM兼容性和性能调整。对于运行托管代码的环境,您应该删除<runtime>部分。