程序执行时检测并安装framework 4.5
本文关键字:framework 安装 执行 检测 程序 | 更新日期: 2023-09-27 18:25:43
我有一个带有target.net 4.5的VS2013 EE WinForms应用程序。当我尝试在没有安装4.5框架的Win7下执行我的应用程序时,会出现异常窗口(0xc000007b)。我应该在我的应用程序设置中设置什么,以显示带有下载框架选项的良好信息窗口?我不想发布安装文件,只想要带有dll-s的exe,所以发布不是我的目标。
try:
http://thecodeventures.blogspot.com/2012/12/c-how-to-check-if-specific-version-of.html
参考msdn
http://msdn.microsoft.com/en-us/library/hh925568.aspx
private static void Get45or451FromRegistry()
{
using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE''Microsoft''NET Framework Setup''NDP''v4''Full''")) {
int releaseKey = Convert.ToInt32(ndpKey.GetValue("Release"));
if (true) {
Console.WriteLine("Version: " + CheckFor45DotVersion(releaseKey));
}
}
}
// Checking the version using >= will enable forward compatibility,
// however you should always compile your code on newer versions of
// the framework to ensure your app works the same.
private static string CheckFor45DotVersion(int releaseKey){
if ((releaseKey >= 379893)) {
return "4.5.2 or later";
}
if ((releaseKey >= 379675)) {
return "4.5.1 or later";
}
if ((releaseKey >= 378389)) {
return "4.5 or later";
}
// This line should never execute. A non-null release key should mean
// that 4.5 or later is installed.
return "No 4.5 or later version detected";
}
关于的种类
您可以在注册表中检查安装了哪个框架?如果VS版本低于4.5,则给出下载该版本的消息窗口。
你可以很容易地找到如何检查VS版本安装?
这是链接http://www.mztools.com/articles/2008/MZ2008003.aspx