Could not install package '--'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5'

流过昼夜 提交于 2020-12-30 04:51:11

问题


I created this package, I need it in a project but couldn't install it, this error appears:

Could not install package 'Mshwf.NiceLinq 1.0.9'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', 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

I don't know why this happen, in another project (Console) I changed the framework to 4.6 and other versions and it wasn't a problem, but this only happen in this project (MVC and Web API):

this is the nuspec file:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>Mshwf.NiceLinq</id>
    <version>1.0.9</version>
    <title>Nice LINQ</title>
    <authors>MShawaf</authors>
    <owners>Mshawaf</owners>
    <projectUrl>https://github.com/mshwf/NiceLinq</projectUrl>
    <iconUrl>https://raw.githubusercontent.com/mshwf/NiceLinq/master/logo.png</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>See it as: WHERE ID IN (1, 2, 3, 7, 9, 22, 30, 101)</description>
    <releaseNotes>Minor changes.</releaseNotes>
    <copyright>Copyright 2016</copyright>
    <tags>LINQ IEnumerable Where Contains Search Filter</tags>
  </metadata>
</package>

回答1:


Your package targets NETFramework,Version=v4.5.2. That means the assembly folder is lib\net452. You are trying to install the package to a higher framework (greater than 4.5) project. Create a project with framework 4.5.2 or rename the package's lib folder from net452 to the version which you want to target like net45 or net46.

You can target multiple framework too from a single package.

Edit your csproj file like this:

<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>

Refer here: https://docs.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks

For a complete, up-to-date list of target framework names, refer to https://docs.microsoft.com/en-us/nuget/reference/target-frameworks#supported-frameworks




回答2:


Go to the folder:

C:\Users\[username]\.nuget\packages\[package name]\1.0.0.4\lib

Rename the folder with the .net version of your project.

Suppose I am using .net framework 4.6.1 my folder name should be net461




回答3:


You can install earlier version like : Install-Package AutoMapper -Version 7.0.1




回答4:


In my case, I was trying to install the package into a WPF App (.Net Framework) while my co-workers prepared the package for .Net Core Project.

Try creating a .Net Core Project(or the type of the targeted project type) and install the packages same way:

Solution Explorer>Right click to Solution>Manage Nuget Packages for solution>Search for the needed package>Install

Checking this before other solutions may save time.




回答5:


In my case, I was trying to insert a package of our own making that we put into our own Nuget feed, so I had access to the project. This is what I did to clear the issue up. In the project solution window, click on the packages.config. In the properties window, change build action to "Content." After pushing it out to our feed again I was able to install it into the main project.




回答6:


I had similar issue which i fixed by removing the packages.config(you can edit the file if you don't want to remove) file and then made sure both the package i was using was built using the same .net version as the Project i was using it in(for me the package was built using 4.6 while my console project was targeting earlier version of .net).




回答7:


Update the Application .NET target framework could solve the problem. In my case, I'm installing EmguCv 4.2 package. I get this same error when trying to build with 4.5.1 .NET target framework. After updated the .NET target framework to 4.6.2, I can install the EmguCv 4.2 Nuget package successfully.




回答8:


Try installing .net SDK here and then right-click on your solution/project and "restore nuget packages"




回答9:


I had this problem with a package I had created and hosted on our own private nuget server, but even after trying others suggestions here such as making sure that the package supported the correct .net framework version, it still wouldn't work.

I got someone else to try and they managed to add it with no problem. Today, messing around in VS's options, I found a fix for this: Options -> NuGet Package Manager -> General -> Clear All NuGet Cache(s)

How to clear nuget cache in visual studio

Hopefully this helps someone who was as confused as I was :D



来源:https://stackoverflow.com/questions/42039069/could-not-install-package-you-are-trying-to-install-this-package-into-a-pr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!