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?
How about this? (multi-targetting rules for FxCop)
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.
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:
You can use the code found here to detect the installed .NET Frameworks.
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.");