问题是我需要知道它是否是3.5SP1版本,Environment.Version()
只返回2.0.50727.3053
。
我找到了this solution,但我认为它会花费更多的时间,所以我正在寻找一个更简单的。有可能吗?
发布于 2017-04-19 20:24:43
在不需要访问注册表的权限的情况下,另一种方法是检查特定框架更新中引入的类的存在。
private static bool Is46Installed()
{
// API changes in 4.6: https://github.com/Microsoft/dotnet/blob/master/releases/net46/dotnet46-api-changes.md
return Type.GetType("System.AppContext, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", false) != null;
}
private static bool Is461Installed()
{
// API changes in 4.6.1: https://github.com/Microsoft/dotnet/blob/master/releases/net461/dotnet461-api-changes.md
return Type.GetType("System.Data.SqlClient.SqlColumnEncryptionCngProvider, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", false) != null;
}
private static bool Is462Installed()
{
// API changes in 4.6.2: https://github.com/Microsoft/dotnet/blob/master/releases/net462/dotnet462-api-changes.md
return Type.GetType("System.Security.Cryptography.AesCng, System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", false) != null;
}
private static bool Is47Installed()
{
// API changes in 4.7: https://github.com/Microsoft/dotnet/blob/master/releases/net47/dotnet47-api-changes.md
return Type.GetType("System.Web.Caching.CacheInsertOptions, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", false) != null;
}
发布于 2009-06-04 18:41:36
Environment.Version()
给出了一个不同问题的正确答案。在.NET 2.0、3和3.5中使用相同版本的CLR。我想您可以在GAC中查看这些后续版本中添加的库。
发布于 2019-06-04 14:53:55
我遇到过这样一种情况:可能会从.NET 4.0或更高版本的程序集中调用我的.NET 4.0类库。
特定的方法调用仅在从4.5+程序集中执行时才起作用。
为了决定是否应该调用该方法,我需要确定当前执行的框架版本,这是一个很好的解决方案
var frameworkName = new System.Runtime.Versioning.FrameworkName(
AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName
);
if (frameworkName.Version >= new Version(4, 5))
{
// run code
}
更新
这在4.0程序集中起作用
var featureEnabled = GetCurrentFrameworkName().Version >=新版本(4,5);
public static FrameworkName GetCurrentFrameworkName()
{
// AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName
// is missing prior to .NET 4.5
var targetFrameworkName = (string)AppDomain
.CurrentDomain
.SetupInformation
.GetType()
.GetProperty("TargetFrameworkName")?
.GetValue(AppDomain.CurrentDomain.SetupInformation, null) ?? ".NETFramework,Version=v4.0.0";
return new FrameworkName(targetFrameworkName);
}
https://stackoverflow.com/questions/951856
复制相似问题