How do I get VS 2017 to install the dependencies for packages that I am trying to install? - visual-studio-2017

I was following a Lynda tutorial that was showing how to add versioning to my APIs. It told me to install the NuGet package Microsoft.AspNetCore.Mvc.Versioning. I tried that and it gave me an error because it needed Microsoft.AspNetCore.Mvc.Core. So I tried to install that package, and, again, another error because it needed another package.
So I started googling for a way to make VS 2017 pull in dependencies with NuGet installation. None of the answers that I found were helpful. I’ve tried managing as packageReference and packages.config. “Allow format selection on first package install” is unchecked. And so on.
So I decided to just power through and add all the dependencies manually. I had to install 29 packages. It took me over half an hour, not including time spent chasing the cat up and down the stairs screaming at the top of my lungs.
Is there some switch I forgot to flip, or some options I didn't add, or does Microsoft really think we might want the option to install a package without installing its dependencies?

How do I get VS 2017 to install the dependencies for packages that I am trying to install?
I have reproduced this issue on my side. This is the correct behavior for nuget. That because the package which you want to install have a indirect dependency Microsoft.AspNetCore.Authentication.Abstractions (>= 2.2.0).
Note: (Version need >= 2.2.0).
However, the default package for the .net core API project also have same indirect dependency Microsoft.AspNetCore.Authentication.Abstractions (>= 2.1.1 && < 2.2.0) with version limit (>= 2.1.1 && < 2.2.0).
Note: version limit (>= 2.1.1 && < 2.2.0).
It conflict with dependency of package Microsoft.AspNetCore.Mvc.Versioning. That the reason why nuget not install the dependencies for package.
To resolve this issue, we just need to update the target framework (Right click project->Properties->Target Framework) from .NET Core 2.1 to .NET Core 2.2 for your .net core API project.
If you do not have the version 2.2.0, please download it from here and install it:
.NET SDKs for Visual Studio
After update the target framework to 2.2, the default package Microsoft.AspNetCore.App will be update to Microsoft.AspNetCore.App 2.2.0, which dependency update to Microsoft.AspNetCore.Authentication.Abstractions(>= 2.2.0 && < 2.3.0). So it compatible with the dependencies of the package Microsoft.AspNetCore.Mvc.Versioning 3.1.1.
Now I can install the package Microsoft.AspNetCore.Mvc.Versioning 3.1.1 with its dependency.
Hope this helps.

Related

Visual Studio 2017 Nuget Install Package Builds Project Instead of Installing / Uninstalling Packages

When importing existing library projects into an existing solution (after I copied them locally from somewhere else), when I try to install or uninstall a Nuget package through the package manager, it justs builds my solution showing me all of the errors I have because the package is not installed. It does nto try to install or uninstall the package. Why is it building my project instead of just installing / uninstalling the bloody package?
Why is it building my project instead of just installing /
uninstalling the bloody package?
It's not default behavior of VS IDE itself.
As for VS2017, if we install a normal package using Package Manager UI, VS will check the compatibility between the package to consume and the current project. If they're compatible, the package will be installed successfully, if not, VS will throw nuget error like NU1202 or others in ErrorList window.
But I'm sure for VS2017, installing/uninstalling won't call a build.
Possible causes of the issue and corresponding suggestions:
1.This behavior results from one third-party extension.
Reset all VS settings => disable all the third-party extensions => restart VS to check if the issue persists. If after the check you find this issue results from one extension, you need to make sure if the extension provides one option to turn on/off the auto-build. Or you may need to disable/uninstall the extension temporarily and contact the author of the extension to post the issue.
You may get more details for trouble-shooting from this similar issue.
2.Custom script(.ps1,.targets) from one specific nuget package causes this.
The authors can place powershell script and PackageID.targets in .nupkg when generating packages. Some of these scrips will execute when we install the package, others will execute when we uninstall the package. See similar issue here.
You can create a new simple console project TestProject in TestProject solution. Then right-click solution=>add=>Existing project to import a new external project. Now let's install the Newtonsoft.Json package to check if the issue disappears. If the issue disappears in new project with Newtonsoft.Json package. I think it indicates one special package you try to install/uninstall may cause the issue.
Hope all above helps and feel free to let me know if there's any update.

Issue with updating NuGet packages (VS2017)

Visual Studio 2017 - Saying "Package restore failed" while updating the NuGet packages as following:
Issue with updating NuGet packages (VS2017)
To resolve this issue, first, you should make sure your Target Framework that is used to compile your android application, Use Latest Platform (Android 8.1 (Oreo)).
Check source: Understanding Android API Levels
Second, if you confirm your Target Framework is Android 8.1 (Oreo), then Select all packages checkbox, and click Update button:
After that, all nuget packages can be updated to latest version.
The reason for this issue:
To find the reason for this issue, change the MSBuild build log to Detailed, Tools->Options->Projects and Solutions->Build and Run->MSBuild project build output verbosity:Detailed.
When you update one of those default nuget packages, in the output you will get following dependencies conflict errors:
NU1107: Version conflict detected for Xamarin.Android.Support.Compat.
Reference the package directly from the project to resolve this issue.
App1.Android -> Xamarin.Android.Support.Design 27.0.2 ->
c (= 27.0.2) App1.Android ->
Xamarin.Android.Support.v7.AppCompat 25.4.0.2 ->
Xamarin.Android.Support.Compat (= 25.4.0.2).
That means when you update the default package Xamarin.Android.Support.Design to 27.0.2, one of its dependencies, Xamarin.Android.Support.Compat also need to be updated to 27.0.2. However, other nuget package Xamarin.Android.Support.v7.AppCompat 25.4.0.2 still reference the Xamarin.Android.Support.Compat with the old version 25.4.0.2. So you will get that error.
To resolve this error, you should update all default package at once instead of one of them.

Using HtmlAgilityPack NuGet package in dotnet core v1.0

I am trying to use HtmlAgilityPack nuget package in netcoreapp1.0 (I am restricted to this version since AWS Lambda supports only it). Which version of the HtmlAgilityPack package should I use? The point is .NETStandardLibrary 1.6.0 is only compatible with netcoreapp1.0 but I don't see any version of HtmlAgilityPack which would be compatible with .NETStandardLibrary 1.6.0. The minimum version I can see is .NETStandardLibrary 1.6.1 but this is for netcoreapp1.1.
From a .NET Standard API prospective nothing changed between NETStandard.Library 1.6.1 and 1.6.0. We only bumped the version of the meta-package so that we could pull in newer versions of the dependent packages which contain implementation fixes but no real new API surface for NS1.6.
See the issue #171 in DotNet standard repo What's the change in NetStandard.Library 1.6.1 vs 1.6.0?
Even if there will be no HtmlAgilityPack compatible (or build against) netstandard1.6, but there is a netstandard1.6.1 I would just build it for myself by replacing netstandard v1.6.1 nuget package with netstandard v1.6 package ( HtmlAgilityPack is open source - right :) ).
Most importantly there is no netstandard1.6.1, it was never released or even worked on, v1.6.1 stands only for the version of NETStandard.Library NuGet package.

What do Yellow Warning Triangles mean on Dependencies in Visual Studio 2017?

I have just converted my PCL library to a new .Net Standard library and I have some Yellow Warning triangles on my Dependencies shown below:
During the conversion it brought all nuget packages across including dependencies so it could be dulicates.
How do I find out what the Yellow warning triangles represent?
EDIT
Build Logs:
To prevent NuGet from restoring packages during build, open the Visual
Studio Options dialog, click on the Package Manager node and uncheck
'Allow NuGet to download missing packages during build.' NU1605:
Detected package downgrade: NUnit from 3.8.1 to 2.6.4. Reference the
package directly from the project to select a different version.
MyProj.UI.Tests -> MyProj.Core.Tests -> NUnit (>= 3.8.1)
MyProj.UI.Tests -> NUnit (>= 2.6.4) NU1605: Detected package
downgrade: NUnit from 3.8.1 to 2.6.4. Reference the package directly
from the project to select a different version. MyProj.UI.Tests.iOS
-> MyProj.UI.Tests -> MyProj.Core.Tests -> NUnit (>= 3.8.1) MyProj.UI.Tests.iOS -> NUnit (>= 2.6.4) NU1605: Detected package
downgrade: NUnit from 3.8.1 to 2.6.4. Reference the package directly
from the project to select a different version.
MyProj.UI.Tests.Android -> MyProj.UI.Tests -> MyProj.Core.Tests ->
NUnit (>= 3.8.1) MyProj.UI.Tests.Android -> NUnit (>= 2.6.4)
As trite as it sounds, try rebuilding then restarting VS - and get on with your day :)
run dotnet restore before you do any complicated manipulation, you are going to be provided with a lot more info than in the error window or solution explorer.
You can run this command in the Package Manager Console:
Tools > NuGet Package Manager > Package Manager Console
If you have the warning icon but no warnings and nothing appears to actually be wrong, right click the project > Unload Project > right click the project again > Reload Project. The icon appeared for a moment and then was cleared for me in Visual Studio 2019. This avoids a full Visual Studio restart.
In the build Log I happened to notice this:
C:\Program
Files\dotnet\sdk\2.0.2\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.DefaultItems.targets(199,5):
warning : A PackageReference for 'NETStandard.Library' was included in
your project. This package is implicitly referenced by the .NET SDK
and you do not typically need to reference it from your project. For
more information, see https://aka.ms/sdkimplicitrefs
I therefore went and uninstalled all packages that were listed as dependencies for the .Net Standard nuget listed here:
.NETStandard 1.1
Microsoft.NETCore.Platforms (>= 1.1.0)
System.Collections (>= 4.3.0)
System.Collections.Concurrent (>= 4.3.0)
System.Diagnostics.Debug (>=> 4.3.0)
System.Diagnostics.Tools (>= 4.3.0)
System.Diagnostics.Tracing (>= 4.3.0)
System.Globalization (>= 4.3.0)
System.IO (>= 4.3.0)
System.IO.Compression (>= 4.3.0)
System.Linq (>= 4.3.0)
System.Linq.Expressions (>= 4.3.0)
System.Net.Http (>= 4.3.2)
System.Net.Primitives (>= 4.3.0)
System.ObjectModel (>= 4.3.0)
System.Reflection (>= 4.3.0)
System.Reflection.Extensions (>= 4.3.0)
System.Reflection.Primitives (>= 4.3.0)
System.Resources.ResourceManager (>= 4.3.0)
System.Runtime (>= 4.3.0)
System.Runtime.Extensions (>= 4.3.0)
System.Runtime.InteropServices (>= 4.3.0)
System.Runtime.InteropServices.RuntimeInformation (>=> 4.3.0)
System.Runtime.Numerics (>= 4.3.0)
System.Text.Encoding (>= 4.3.0)
System.Text.Encoding.Extensions (>= 4.3.0)
System.Text.RegularExpressions (>= 4.3.0)
System.Threading (>= 4.3.0)
System.Threading.Tasks (>= 4.3.0)
System.Xml.ReaderWriter (>= 4.3.0)
System.Xml.XDocument (>= 4.3.0)
And the yellow warnings disappeared.
From here: https://blogs.msdn.microsoft.com/dotnet/2017/08/14/announcing-net-standard-2-0/
I have also found you can use the NoWarn property like below:
<ItemGroup>
<PackageReference Include="Huitian.PowerCollections" Version="1.0.0" NoWarn="NU1701" />
</ItemGroup>
The yellow triangle means that the package physical file(s) is gone and no longer available on the Hard Drive.
This usually happens when issuing a get latest version request on source control in TFS, especially when using a new machine, and you want to get your project code from the TFS server.
It can also be caused by low quality internet connection which almost always will result in data loss, or corrupted downloaded files.
If the problem is missing a couple of packages, you can modify the packages.config file and remove these packages from the packages.config and re-install the missing packages via nuget packages manager.
But if the problem is missing more than a few packages, the best and fast way I use to retrieve missing packages is by:
Opening a new instance of visual studio
Create a new project solution with same project type like the one with missing packages (Example: ASP.Net MVC with Individual User Account)
Update the packages of the new project to the latest to match the packages versions of the previous project solution
Open the file explorer and navigate to packages folder in the new solution that you created
Copy all contents of folder Packages by selecting all, Note do NOT copy the Packages folder itself only the contents inside the folder
Paste that in your previous solution ( solution with the missing packages), in the Packages folder with overwrite existing items.
Go to your packages folder in the solution explorer and expand it, then click the refresh button to see that many of missing packages are now showing without yellow triangle
Lastly you will end up with a couple of missing packages, that are not included by default when you create new solution, you need to remove them from your packages.config file (the file which nuget package managers) reads to determine installed packages, and install those as new using the nuget package manager.
Note such problems related to missing files from projects are always hard to fix, and depends on developer experience, so don't expect an easy solution for this one.
On the cause of the error,Microsoft says it is a bug, but it can happen on any version of Visual Studio.
For any new person with this issue: try this and you will remember me :D
Go to: Tools > NuGet Administrator > Configurations and verify that you have Allow nuget... and automatically check... checked.
After that, the only thing you have to do is click on the button "Clear All NuGet Cache(s)"!
That's it. You don't have to edit anything manually; that can be dangerous, believe me, I used to need to do some of the steps described here a lot of the time.
If you want to try the official Microsoft solution for this issue, you could check it here: https://learn.microsoft.com/es-es/nuget/consume-packages/package-restore#restore-packages-automatically-using-visual-studio
But just cleaning the cache solved all the problems for me.
I just had this issue in VS2019 version 16.8.3 when renaming a .NET Core 3.1 project. Directly after renaming the project the yellow triangles appeared. Rebuild, clean, etc. nothing worked. Closing and reopening the solution solved it for me.
Oddly enough, my .Net Core 3 project needed me to simply click "Load project dependencies" from the context of the project, then the warning icon disappeared.
Helpful screenshot:
The yellow exclamation sign is usually because of missing references or unsupported dll. If you clone a repository then there are chances that many of the nugget packages will show yellow exclamation. If you have verified the project version and still, the problem exists you can try the below solution.
In the package manager console, select the project in which you are facing this problem and then type the following command.
Update-Package -Reinstall
This will force reinstall all the packages. This command will not update the version of NuGet packages, it will simply force reinstall them.
This solution worked in my case. I am using VS2019. Hope this will help others as well.
-unload project
-load project
This worked for me.
It will help if you
remove bin folder and obj folder
clean the project
Better also to remove the cached packages from C:\Users\{user}\.nuget\packages
Then restore the packages. that work for me.
dotnet restore
If I try to uninstall Microsoft.NETCore.Platforms as stated in the marked answer I get the following error:
Unable to uninstall 'Microsoft.NETCore.Platforms.1.1.0' because 'NETStandard.Library.2.0.3' depends on it.
I uninstalled the other packages, but I still get the NETSDK1023 error:
A PackageReference for 'NETStandard.Library' was included in your project. This package is implicitly referenced by the .NET SDK and you do not typically need to reference it from your project. For more information, see https://aka.ms/sdkimplicitrefs
Now I edited my .csproj and deleted the following part
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
as stated in https://aka.ms/sdkimplicitrefs under Recommendations:
When targeting .NET Core or .NET Standard, never have an explicit reference to the Microsoft.NETCore.App or NETStandard.Library metapackages via a <PackageReference> item in your project file.
Now the warning is gone!
I faced this error when I clone the project. the main reason was the Nuget packages couldn't restore and I find a solution by making nuget.org only active resource.
Make sure you select Nuget.org as only active resource.
Hope it helps
I had the same issue , after banging my head 2 days I found that this is because
Long path was not allowed
For example two class libraries in my project had name length > or = 40
So they were not loading dependency of netstandard2.0
If you have the same case , You need to first update long path limit from registry and set its value to 1
see https://www.thewindowsclub.com/how-to-enable-or-disable-win32-long-paths-in-windows-11-10
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
Like I said in another post, about the same issue, this is only for documentation... I know that this was ready to solve it, and one of my answers was ready to say something about that, but, maybe some of you present the same error and none of this solution listed here solves the problem... I don't know why this problem comes with the global installation of .net 6, but, if you present this issue again, you need to go to
C:\Users\YourUsername.nuget
And delete all the content, don't be afraid, that's a cache generator than will be created again if is need it.
I just updated Visual studio to 16.4.4 and the issue was resolved.
The reference is fixed and no more yellow triangle.
Thanks.
I had the triangles on referenced projects dependencies. I had added reference of
System.Drawing.dll
.There was also warning in error list box .
Removing it solved the problem for me.
You know ,according to warning in error list System.Drawing.dll has forwarded to System.Drawing.Common
and you need to install it through Manage NuGet Packages .
Now it works properly.
Go to your project/solution directory and execute:
dotnet restore
Then you are done!
I just Mapped my local folders to the tfs code branch and had these issues,
I had to look into the project Build order, clean them one by one in order and build them after cleaning.(Or you can try cleaning the whole solution and build it again)
You can look into the project build order by Select the Solution > Project (From Top) > Build Order
I had taht issue, when changing the output directory:
<BaseOutputPath>$(SolutionDir)</BaseOutputPath>
As soon as i deleted that property, everything worked fine! (VS 2022 v17.0 btw)
None of the above worked for me. I had one project in the solution with warning triangles on the dependencies to other projects in the solution which caused lots of red errors in VS. However, it would build, run and debug just fine. I finally unloaded the project with a right click on the project name in the solution tree, and then reloaded the project and all is happy now. Thanks Visual Studio, smh. I am using VS 2019 16.7.1
Right click on Solution and Rebuild Solution.
It worked for me.
I had the triangles on referenced projects dependencies. I just removed and added the dependencies to remove the triangle.
I am posting this answer just because no other solutions presented here helped me.

Package X is not compatible with netstandard2.0

I created a .NET Standard v2.0 project in Visual Studio 2017 v15.3.1 and I'm unable to install "Microsoft.EntityFrameworkCore 2.0.0" package in it (by Nuget 4.3). Previously the .NET SDK and Runtime, both 2.0.0, were installed.
The errors I get follow this pattern:
"Package X is not compatible with netstandard2.0 (.NETStandard,Version=v2.0)." (i.e. System.Reflection.TypeExtensions 4.1.0).
What could it be causing these errors?
EDIT: I'll show the exact warnings and errors with an example (there are too many).
Restoring packages for [.csproj path]...
Warning:
Package "System.Collections 4.3.0" was restored using ".NETFramework,Version=v4.6.1" the project target framework ".NETStandard,Version=v2.0". This may cause compatibility problems.
...
Error:
Package Remotion.Linq 2.1.1 is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Package Remotion.Linq 2.1.1 supports:
net35 (.NETFramework,Version=v3.5)
net40 (.NETFramework,Version=v4.0)
net45 (.NETFramework,Version=v4.5)
netstandard1.0 (.NETStandard,Version=v1.0)
portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259)
...
Error restoring package. Reverting package changes for 'ClassLibrary1'.
Time elapsed: 00:00:02.4689637
========== Ended ==========
Clicking the "Clear all Nuget Caches" will resolve issue.
Issue solved installing, independently, newer versions for each of the packages' dependencies which were showing error, so that the big package "Microsoft.EntityFrameworkCore 2.0.0" gets installed at last.
Hope it helps.
Edited: It happened to me another time and tried a faster solution. The key was deleting Nuget's cache from the packages' manager configuration.