简体   繁体   English

检测.NET Framework 3.5 SP1依赖性(cmp.3.5 w / o SP1)

[英]Detect .NET Framework 3.5 SP1 Dependency (cmp. 3.5 w/o SP1)

I'm using 3.5 SP1 on my machine, while our customers currently use 3.5 without SP1. 我在我的机器上使用3.5 SP1,而我们的客户目前使用3.5不带SP1。 I don't know any way in VS2008 to target the solution or project to 3.5 without SP1, only the 3.5 with SP1 I have installed. 我不知道VS2008中的任何方法将解决方案或项目定位到没有SP1的3.5,只安装了我带有SP1的3.5。

If we use functions or constructors not available in 3.5 w/o SP1 the code will not work properly. 如果我们使用3.5 w / o SP1中不可用的函数或构造函数,代码将无法正常工作。

That is, I want to detect at compile time what would not work without SP1. 也就是说,我想在编译时检测没有SP1的情况会有什么效果。

So far we have done testing (in a VM or separate machine) to see if the application breaks, and it does break sometimes when we've used parts of the API not available until SP1. 到目前为止,我们已经完成了测试(在VM或单独的机器中)以查看应用程序是否中断,并且当我们使用的部分API在SP1之前不可用时,它确实会中断。 The problem is that it only breaks when the code actually runs (at runtime), not when the assembly is loaded. 问题是它只在代码实际运行时(在运行时),而不是在加载程序集时中断。

One solution would be to have a machine with VS2008 w/o SP1 and try to compile the project. 一种解决方案是使用VS2008 w / o SP1的机器并尝试编译项目。 However I'd prefer some tool to help me detect a dependency to 3.5 SP1 (due to use of new API, or whatever), either by analyzing the source code, or the assemblies we produce. 但是,我希望通过分析源代码或我们生成的程序集来帮助我检测对3.5 SP1的依赖性(由于使用新的API,或其他)。

My google powers has not been strong enough with this question, any hints? 我的谷歌权力对这个问题,任何提示都不够强大?

I just had the same problem, and I found a solution. 我遇到了同样的问题,我找到了解决方案。 For our application, it was a call to System.Threading.WaitHandle.WaitOne(Int32) that got us in trouble. 对于我们的应用程序,它是一个调用System.Threading.WaitHandle.WaitOne(Int32)让我们陷入困境。 For more details on how references to API's that were introduced in service pack releases can leak into your code without Visual Studio noticing, see Krzysztof Cwalina's post . 有关如何在没有Visual Studio注意的情况下将Service Pack版本中引入的API引用泄漏到代码中的更多详细信息,请参阅Krzysztof Cwalina的帖子

The good news is that, as Marc mentioned is his answer , FxCop has a new rule that detects these leaks. 好消息是,正如Marc提到的那样,FxCop有一个新的规则来检测这些泄漏。 The bad news is that the rule is broken in FxCop 1.36 when you target .NET Framework 3.5. 坏消息是,当您使用.NET Framework 3.5时,FxCop 1.36中的规则被破坏了。 However, David Kean describes how to edit a couple of XML configuration files to fix the problem . 但是,David Kean描述了如何编辑几个XML配置文件来解决问题 I followed the instructions, and FxCop now detects my references to service pack API's. 我按照说明操作,现在FxCop检测到我对Service Pack API的引用。

How about this ? 怎么样这个 (multi-targetting rules for FxCop) (FxCop的多目标规则)

您可以使用此处的代码来检测已安装的.NET框架。

string Fx35RegistryKey = @"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3.5"; string Fx35RegistryKey = @“HKEY_LOCAL_MACHINE \\ SOFTWARE \\ Microsoft \\ NET Framework Setup \\ NDP \\ v3.5”; object Fx35ServicePack = Registry.GetValue(Fx35RegistryKey, "SP", null); object Fx35ServicePack = Registry.GetValue(Fx35RegistryKey,“SP”,null);

if (Fx35ServicePack == null || (int)Fx35ServicePack < 1) throw new Exception(".NET Framework 3.5 SP1 is required."); if(Fx35ServicePack == null ||(int)Fx35ServicePack <1)抛出新的异常(“.NET Framework 3.5 SP1是必需的。”);

There's another option that I haven't tried. 我没有尝试过另一种选择。 The Visual Studio documentation says that you can make your ClickOnce installer specifically target the .NET 3.5SP1 framework. Visual Studio文档说您可以使ClickOnce安装程序专门针对.NET 3.5SP1框架。 Follow the link, and search for "Targeting .NET Framework Version 3.5 SP1". 按照链接,搜索“Targeting .NET Framework Version 3.5 SP1”。 Essentially, it says doing any of the following will force the installer to install 3.5SP1: 从本质上讲,它表示执行以下任何操作都会强制安装程序安装3.5SP1:

  • Specify an Error URL in the Publish Options dialog box. 在“发布选项”对话框中指定错误URL。
  • Specify a Suite name in the Publish Options dialog box. 在“发布选项”对话框中指定套件名称。
  • Create a desktop shortcut in the Publish Options dialog box. 在“发布选项”对话框中创建桌面快捷方式。
  • Exclude a file from the hash in the Application Files dialog box. 从“应用程序文件”对话框中的散列中排除文件。
  • Clear the Sign the ClickOnce manifests check box on the Signing page. 清除签名页面上的签署ClickOnce清单复选框。
  • Add a reference to the System.Data.Entity assembly. 添加对System.Data.Entity程序集的引用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM