简体   繁体   English

如何使用.Net Framework 3.5或4.5取决于哪些可用

[英]How to use .Net Framework 3.5 or 4.5 depending on which ever is available

My app uses .net 3.5 , and compiles successfully under 4.5 without any modifications, so apparently the libraries my app uses exists both in 3.5 & 4.5. 我的应用程序使用.net 3.5 ,并在4.5下成功编译而没有任何修改,因此显然我的应用程序使用的库都存在于3.5和4.5中。 But windows 8 explicitly requires 3.5 even though 4.5 is available. 但是,即使4.5可用, Windows 8也明确要求3.5。

How can I (programatically) make my app use 3.5 when running on windows7 and 4.5 when running on windows8? 在windows8上运行时,如何(以编程方式)使我的应用程序在windows7和4.5上运行时使用3.5?

PS: Ideally I want to avoid using an app.config file PS:理想情况下我想避免使用app.config文件

The only thing I could think to do, is to compile for both frameworks. 我唯一能想到的就是编译两个框架。 And include both in your installer package, using it to install the correct one based on what you find on the system. 并在您的安装程序包中包含它们,使用它根据您在系统上找到的内容安装正确的安装程序包。

For App developers (and IT Administrators): IT administrators can configure .NET 3.5 apps to run on either .NET 3.5 or .NET 4.5 (depending on what's already installed). 对于应用程序开发人员(和IT管理员):IT管理员可以将.NET 3.5应用程序配置为在.NET 3.5或.NET 4.5上运行(取决于已安装的内容)。 In order to run a managed app on either 3.5 or 4.5, just add a section in the application configuration file. 要在3.5或4.5上运行托管应用程序,只需在应用程序配置文件中添加一个部分即可。 This will ensure that if .NET 3.5 is installed, the app will run on .NET 3.5; 这将确保如果安装了.NET 3.5,该应用程序将在.NET 3.5上运行; otherwise the app will run on .NET 4.5. 否则该应用程序将在.NET 4.5上运行。 An example of the additional section in the configuration file is provided below: 下面提供了配置文件中附加部分的示例:

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

I didn't find a solution which didn't have a dependency on an additional file. 我没有找到一个没有依赖于附加文件的解决方案。 But the simplest way I could get my .net 3.5 app to work on windows 8 was creating an app.config file(which I wanted to avoid) and adding the " <supportedRuntime> " element. 但是,我可以让我的.net 3.5应用程序在Windows 8上运行的最简单方法是创建一个app.config文件(我想避免)并添加“ <supportedRuntime> ”元素。

<configuration>
  <startup>
    <supportedRuntime version="v4.0" /> 
  </startup>
</configuration> 

Win8 will detect the need for 3.5 and seamlessly prompt the user to install it. Win8将检测到3.5的需求并无缝地提示用户安装它。 Not really worth jumping through hoops to further streamline 不值得跳过篮球进一步精简

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

相关问题 将.NET配置为在Windows 7和Windows 8上使用3.5和4.5 - Configure .NET to use 3.5 on Windows 7 and 4.5 on Windows 8 Reactive框架是否可用于.NET Framework 3.5? - Is the Reactive framework available for .NET Framework 3.5? 通过将/ net framework 4.5降级到3.5来兼容实体框架 - Compatibility Entity Framework by downgrading /net framework 4.5 to 3.5 用于C#应用程序的Retromigration 4.5至3.5 .net框架 - Retromigration 4.5 to 3.5 .net framework for c# application 如何在VB.NET中使用Action(of IDataReader)(.NET Framework 3.5) - How to use Action (Of IDataReader) in VB.NET (.NET Framework 3.5) NET Framework 4.5中如何使用System.Configuration.DpapiProtectedConfigurationProvider版本2? - How to use System.Configuration.DpapiProtectedConfigurationProvider version 2 in .net framework 4.5? 如何在 Unity 5 中使用 .NET 框架 4.5 - How can I use .NET framework 4.5 in Unity 5 我可以在.NET 4.5中使用Windows Identity Foundation 3.5吗? - Can I use Windows Identity Foundation 3.5 with .NET 4.5? 如何在.NET Framework 3.5上使用Stream.CopyTo? - How to use Stream.CopyTo on .NET Framework 3.5? 如何在.NET Framework 3.5上使用System.Threading.Tasks类 - How to use the System.Threading.Tasks Class on .NET Framework 3.5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM