3

We were under the impression that setting the target framework on the properties of a solution would limit that app to using only that framework or below's functionality. We just found out though, that someone can add a reference and start using code from a higher versioned framework and the compiler won't complain one bit. Since we would like to prevent this in the future does anyone have any ideas on how I could detect something referencing a higher version or not? I need to fail the build if someone adds code above our target.

1
  • imho that flag only disallows language (clr) features of higher frameworks, not libraries.. Commented Nov 1, 2009 at 2:04

2 Answers 2

1

Assuming you're targeting .NET 2.0 and above... your build could fail if you detect references to System.Core or other 3.x assemblies (e.g. WPF) in References of your projects.

UPDATE

You could start with checking inside each .PROJ file for:

<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>

Then, inside the <ItemGroup> tag:

<Reference Include="System.Core">
  <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
  <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
  <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>

This could be a custom NAnt task or write your own parser to look for these nodes and fail the build.

Sign up to request clarification or add additional context in comments.

1 Comment

And how would you detect these? I have looked at the manifests, the proj files, and alike. And, without a global list of each dll and which version it is in I cannot figure out how to best determine. Good news is I have tested VS 2010 and it does enforce this, so the best option just may be to wait for 2010 and upgrade immediately.
0

Why do you need to prevent this if it works? As long as you don't use any of the new features, I believe it is possible to have "forward" compatible DLLs.

2 Comments

We wish to make sure a developer doesn't accidently/unknowingly add use any of the new features.
I would expect the compiler to catch these problems for you. If not the compiler, then any unit tests would catch it for sure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.