Target nuget packege for multiple framework

When you’re building a .Net liibrary you have to take in care which framework the end user will use. In order to avoid user’s framework upgrade/downgrade we must target multiple frameworks in the nuget package.

Library project configuration

First, in your .csproj file, create separate build configurations. I created “Debug” | “Release” and “Debug45” | “Release45” for the target frameworks 4.6.1 and 4.5 respectively. I manually set the OutputPath and added theTargetFrameworkVersion element to each configuration:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug45|AnyCPU'">
    <OutputPath>bin\Debug45\</OutputPath>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release45|AnyCPU'">
    <OutputPath>bin\Release45\</OutputPath>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>

In this way you can build the library with different target framework.

Targeting Multiple Frameworks in NuGet

In the folder created for the nuget package divide the lib folder by adding for each targeted framework the relative folder where you will add the relative library .dll file.

The lib folder looks like this:

  • lib
    • net45
    • net461

Now you can run nuget.exe pack MyAssembly.nuspec

A new package is created.

When you refer this package through Nuget package manager from a VS solution, your reference automatically link the dll related to your project framework.

Advertisements

Setting up the MS.NET Enterprise Environment for Application Development

A new machine configuration for Microsoft development software.

Developer

  1. Install Visual Studio 2010 from DVD
  2. Install Team Explorer (.iso) from http://www.microsoft.com/download/en/details.aspx?id=329
  3. Install Visual Studio 2010 SP1 from http://www.microsoft.com/download/en/details.aspx?id=23691

Database

  1. Install Microsoft SQL Server 2008 R2 RTM – Express with Management Tools from http://www.microsoft.com/download/en/details.aspx?id=23650
  2. Install Microsoft® SQL Server® 2008 R2 Service Pack 1 from http://www.microsoft.com/download/en/details.aspx?id=26727
  3. Otherwise (1-2) you can download and install these products separately:

Windows Phone

  1. Install Windows Phone SDK (actual SDK 7.1) from http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=27570
  2. Verify and install Windows Phone Developer Tool Update from http://www.microsoft.com/download/en/details.aspx?id=23854

Silverlight

  1. Install the latest version of Silverlight SDK (check Microsoft’s Web Site – actual version 5.0.x)
  2. Install Silverlight Toolkit based on last installed version
  3. Install Silverlight for Windows Phone Toolkit (actual release september 2010) from http://silverlight.codeplex.com/releases/view/52297

Kinect

  1. Install Microsoft Kinetic SDK (Beta version) from http://research.microsoft.com/en-us/um/redmond/projects/kinectsdk/download.aspx

Azure

  1. Install Windows Azure SDK e VSCloudService (actual version 1.4) from http://www.microsoft.com/download/en/details.aspx?id=15658
  2. Otherwise (1) you can download and install Windows Azure SDK All-in-one (actual september 2010) from http://www.microsoft.com/windowsazure/sdk/

Microsoft Web Platform

You can complete your installations with the Microsoft Web Platform availabe at http://www.microsoft.com/web/downloads/platform.aspx

Visit Microsoft’s web site for latest updates