Multi-targeting framework libraries

Today, I’ve a new demand: How to create a .NET library available for .NET 3.5 and .NET 4.0.

The first solution is to create the library with the framework 3.5 and use it in 4.0… but that’s not the best solution.

The easier solution is to create a Visual Studio solution with references to two projects. Each project sets the correct framework (in project properties) and defines a compilation constant (NET35 or NET40) with MSBuild configuration (see below).

I’ve opened each .csproj to add this MSBuild script (adapted for 3.5 or 4.0):

    <TargetFrameworkName>.NET Framework 3.5</TargetFrameworkName>

Next, we can use a precompilation constants to check which version of framework is used.

  #if NET35
    // Code used only with framework 3.5
Tagged with: ,
Posted in Tips and others

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow me
   RSS Feed    Twitter    Linked In

Write you email address to subscribe at this blog and to receive new posts by mail.

Join 611 other followers

Who I am?

%d bloggers like this: