views:

1782

answers:

5

I'm using 3.5 SP1 on my machine, while our customers currently use 3.5 without 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.

If we use functions or constructors not available in 3.5 w/o SP1 the code will not work properly.

That is, I want to detect at compile time what would not work without 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. 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. 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.

My google powers has not been strong enough with this question, any hints?

+2  A: 

How about this? (multi-targetting rules for FxCop)

Marc Gravell
I've just tried FxCop 1.36 (standalone). Using a version of our application known to be using the SP1 API, I was still not able to locate the 3.5SP1 uses.
L. Kolmodin
+1  A: 

You can use the code found here to detect the installed .NET Frameworks.

Thedric Walker
Thanks, but I already know exactly which version is installed. This is an inhouse product, and the environment is well specified. The troubles we're having is to not accidentally use code from SP1 as the workstations can't run it.
L. Kolmodin
A: 

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

if (Fx35ServicePack == null || (int)Fx35ServicePack < 1) throw new Exception(".NET Framework 3.5 SP1 is required.");

This is similar to an previous answear and also only works in runtime. My question is primarily about something during compile time.
L. Kolmodin
+5  A: 

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. 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.

The good news is that, as Marc mentioned is his answer, FxCop has a new rule that detects these leaks. The bad news is that the rule is broken in FxCop 1.36 when you target .NET Framework 3.5. However, David Kean describes how to edit a couple of XML configuration files to fix the problem. I followed the instructions, and FxCop now detects my references to service pack API's.

Don Kirkby
A: 

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. Follow the link, and search for "Targeting .NET Framework Version 3.5 SP1". Essentially, it says doing any of the following will force the installer to install 3.5SP1:

  • Specify an Error URL in the Publish Options dialog box.
  • 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.
  • Add a reference to the System.Data.Entity assembly.
Don Kirkby