Nuget install failed: the package does not contain any assembly references or content files that are compatible with that framework - azure-devops

If I understand Scott Hanselman's post here correctly then I should be able to reference a .net standard library from a framework 4.7.2 solution.
I want to use Nuget to install such a reference.
I am using Azure DevOps Artifacts for the Nuget package. When I push my .net standard solution I can see that the package does create and that the Nuget install command is
Install-Package SBD.Standard -version 2.0.0-CI-etc
However when I try this at the PM console for my framework 4.7.2 project I get
Could not install package 'SBD.Standard 2.0.0-etc'. You are trying to install this package into a project that targets
'.NETFramework,Version=v4.7.2', but the package does not contain any assembly references or content files that are compatible with that
framework
moreover I do not see SBD.Standard as an avialable package in the relevant feed from within VS2019 -> Manage nuget packages for solution.

I think I need packages.config
I was able to create a new 4.7.2 project and add the nuget package that used .net standard 2.0 (but not 2.1)
When I tried to add the nuget package I got a dialog asking me to select the Nuget package manager format
so I chose Packages.config and that worked.

I am not sure I have it right. I solved my problem but am not sure whether this was it after all. SInce PackageReference is more recent it should work.
Some additional explanations for this issue.
There is an issue for NuGet restore when you using new SDK-based project type or PackageReference in the .net framework:
https://github.com/NuGet/Home/issues/5461
https://github.com/dotnet/sdk/issues/1755
When we use packages.config projects or non-SDK based project type, NuGet do not check compatibility during install/restore.
So, to resolve this issue, we need make sure the referenced project is an old style csproj or use packages.config.
That the reason why the packages.config works for you.
Hope this helps.

Related

Nuget command to replace existing references with nuget references?

In VS2017 I created a new Winforms project using the XAF Solutions Wizard ( Entity Framework Code - First)
The wizard adds references according to options I select.
Now I want to change all the packages to use my Nuget Feed for the Dev Express References.
XAF does have Nuget packages
Is there a Nuget command that I can use to do this automatically?
Cross posted to Dev Express
There is no way to do this with Nugets unless you script your way out as we are doing in XAF community project expandFramework. For some cases it won't work, however for a similar case here is what we do.
Parse all your projects for References start with DevExpress and construct a list of assemblies
For all assemblies in the list add them to packages.config
For all assemblies use the DevExpress.PackageContent project to link to the containing the packages.
Get-DxNugets 18.2.6
Install the found packages from step 3
`Nuget Install packageName -OutputFolder $commonOutputFolder
Update the DevExpress references HintPath to the packages installation folder.
Update-HintPath -OutputPath "$packageInstallationfolder" -SourcesPath $rootPath -filter "DevExpress*"
all powershell functions come from the XpandPosh project. There are many helpful methods there unfortunately no docs. But you can get support

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

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>
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://learn.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://learn.microsoft.com/en-us/nuget/reference/target-frameworks#supported-frameworks
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
You can install earlier version like : Install-Package AutoMapper -Version 7.0.1
The .NET Target Framework version is most likely too old. I have VS 2017 and my default Target Framework for a new .NET Framework project was 4.0. I initially tried to install the RestSharp package but it failed with an almost identical message as in this post 'Could not install package ...' However, when I went to Project | Properties | and Application I was able to change the Target Framework to .NET Framework 4.6.1 and then it installed fine.
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.
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.
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).
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.
Try installing .net SDK here and then right-click on your solution/project and "restore nuget packages"
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
In my case I tried to install Itext7 package my project .NET framework was 4.5
I changed my project .NET framework to .NET 4.6.1 by using the following steps then I installed the package successfully :
1- right click the project and click properties
2- Under application tab change the Target framework to the required framework for your package
I could not install OpenTK package in .NETFramwork app but i had success with .NET Core project
Check the supported version from "C:\Users \ [username] \.nuget\packages
[package name]\1.0.0.4\lib".
Go to Project > Right click and select Properties > Application > Target Framework
Change the Target Framework to the supported version
In my case supported version is net462 for the library

Private NuGet v.3 feed

I have a private NuGet 2.8.5 feed in my internal network, which I use as part of my environment.
I just found that it does not work with some new packages.
Particularly, this package reference the same assembly for two different evironments - DNX 4.5.1 and DNXCore 5.0
That causes following error:
'xunit.runner.dnx' already has a dependency defined for
'Microsoft.Framework.Runtime.Abstractions'.
It looks like NuGet v.2 problem.
NuGet Package Explorer UI tool has exactly the same problem...
So, how can I create a local NuGet v.3 feed, which could serve such packages?
This NuGet.Server package looks abandoned, and I'm not able to find its source code anymore...
A 2.8.6 version of Nuget.Server package got posted yesterday, probably after your post. Perhaps this will fix the problem?
https://www.nuget.org/packages/nuget.server

NuGet and Portable Class Libraries - Package doesn't target any framework

I have been using NuGet to manage my internally created assemblies for a few months, and it's working very well. I recently 'discovered' portable class libraries, which has also been great - until it's time to install the packages.
Say I have a PCL that targets .NET 4.5, SL5 and .NET for Windows Store Apps. I run nuget spec to create the .nuspec file, edit the values, package it up, and add the .nupkg to our internal feed. If I open the .nupkg file in the Package Explorer, I see one content folder under lib called portable-win+net45+sl50.
When I try to install the package from any compatible project in another solution, I get the following message:
"'Project.PCL' could not be installed because it is not compatible with any project in the solution. The package doesn't target any framework."
If I manually create the .nupkg in the Package Explorer, updating the version number, adding a lib folder for each targeted framework (not a portable folder) and added the Project.PCL.dll to each folder, I can add the package to the compatible projects in the solution. But to do this process every time I want to update a PCl is somewhat tedious (I had been creating a little .cmd file in the project root folder to quickly package and deploy).
Do other people have this problem? How can I package PCL's in the same way as other types of projects?
Note - I'm using VS 2012 Ultimate and NuGet 2.2
It sounds like maybe nuget spec doesn't work for Portable Class Libraries - that's worth starting a thread or filing an issue on the NuGet site.
However, you can also create a .nuspec file from NuGet Package Explorer. Just create the package as you already did, but then choose "Save Metadata As..." to save it as a .nuspec. Afterwards you may need to edit the source paths in the nuspec file manually, but you should be able to automate the creation of the package.
For me nuget spec and nuget pack worked fine with a portable project while creating the package and installing it on a compatible project.
Do you want to check if you have the latest nuget.exe (2.2), it can be downloaded from http://nuget.org/nuget.exe or can be updated by running nuget update -self

nuget error installing protobuf-net on portable library

I'm trying to install protobuf-net (2.0.0.602) in a portable class library, I just can't seem to get this to work. I get this error:
PM> install-package protobuf-net
'protobuf-net 2.0.0.602' already installed.
install-package : Could not install package 'protobuf-net 2.0.0.602'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.0,Profile=Profile4', 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.
Inspecting the package it appears to target portable-sl4+wp71+windows8, however when i create a vinalla project targeting these frameworks I can't get it to work (profile4 is listed above, but I've tried a few different ones to see what sticks). I've just updated nuget in studio. Running 'nuget' from the package manager console shows the nuget version as 2.1.31022.9038.
If I browse to the protobuf-net.dll within the package (under lib\portable-sl4+wp71+windows8) it will allow me to reference it and all is good.
I can just manually add it, but am I missing something obvious.
Any help appreciated.
This appears to be just a slight tweak needed to the nuget config; I had specified portable-sl4+wp71+windows8, when actually I needed to specify portable-sl4+net4+wp7+windows8, to include regular .NET.
This is fixed in 2.0.0.611, which has been pushed to NuGet.