[Solved] Could not install package ‘Api2Pdf 1.0.1’. Project that targets ‘.NETFramework,Version=v4.5.1’

October 26th, 2018 / by api2pdf /

Intro

You may get this error if you are trying to install a package via NuGet into your .NET application. The full error reads something like:

Could not install package ‘Api2Pdf 1.0.1’. You are trying to install this package into a project that targets ‘.NETFramework,Version=v4.5.1’, but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

The above error is specific to trying to install the Api2Pdf .NET client library (on Github here), but it is not specific to Api2Pdf. You may get a similar error with any package.

Why is it happening?

What this typically means is that the .NET framework that the library was compiled in is a newer version than the one you are running your .NET project on. Api2Pdf’s client library was written and compiled in .NET 4.6.1 and also works in .NET Core.

Solutions

Option 1) The immediate fix would be to change the target framework of your project from .NET 4.5 to .NET 4.6.1 by right-clicking your project in Visual Studio, click Properties, and then change the target framework like so: https://s3.amazonaws.com/vo-random/ShareX/2018/09/ShareX_2018-09-27_06-57-40.png.

Option 2) If you cannot change your target framework to 4.6.1 for whatever reason, then you can simply write c# code against our REST API. The NuGet package is just for convenience but consuming the REST api is very easy. Documentation is here: https://www.api2pdf.com/documentation. And you can even look at the source code for the c# library here: https://github.com/Api2Pdf/api2pdf.dotnet/tree/master/Api2Pdf.DotNet and just copy / paste the code yourself. It’s very simple code.

 

Tags: , ,

Comments are closed.