bwest
bwest

Reputation: 9814

Is it possible to exclude nuget dependencies for target framework versions above NET40?

I have a library that has NuGet package dependencies on a few Microsoft BCL libraries in order to use some .NET 4.5 features but maintain compatibility with .NET 4.0.

Here is the relevant part of packages.config

<packages>
  <package id="Microsoft.Bcl" version="1.0.19" targetFramework="net40" />
  <package id="Microsoft.Bcl.Async" version="1.0.16" targetFramework="net40" />
  <package id="Microsoft.Bcl.Build" version="1.0.10" targetFramework="net40" />
  <package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net40" />
</packages>

Since these libraries are not necessary in .NET 4.5 and above, I'd like to exclude the dependencies for anything above .NET 4.0.

Is this possible without maintaining a second project file? Thanks.

Upvotes: 4

Views: 1418

Answers (2)

Ilya Kozhevnikov
Ilya Kozhevnikov

Reputation: 10432

http://docs.nuget.org/docs/reference/package-manager-console-powershell-reference

Install-Package
  -IgnoreDependencies
      Installs only this package and not its dependencies.

Upvotes: -1

mxpv
mxpv

Reputation: 956

If you want to have only one project file, you may create several build configurations and use msbuild conditions in csproj file:

<ItemGroup Condition="'$(Configuration)' == 'ReleaseNet40'">
  <Reference Include="Microsoft.Threading.Tasks">
    <HintPath>..\packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
  </Reference>
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)' == 'ReleaseNet40'">
  <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'ReleaseNet45'">
  <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>

Upvotes: 3

Related Questions