nuget package reference blue icon in visual studio 2017 - visual-studio-2017

For some reason in my console app, couple of the reference that I installed thru nuget shows the blue nuget icon. I can build my project locally, but not after I deploy my project to cloud. The error msg is complaining about not able to find these 2 references. Seems like I can't delete them either by right click(no delete option avaialble). Any idea?

nuget package reference blue icon in visual studio 2017
That because you are using the packagereference on the project types that are not .NET Core.
You can edit the .csproj file and check if it contains following ItemGroup:
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
</ItemGroup>
To resolve this issue, you can delete this PackageReference from your project file, then add those package with nuget package.
Besides, you should check if you have set the Default package management format to PackageReference. If yes, change it to packages.config, then add those two packages with nuget:
Hope this helps.

Happened to me in VS 2022.
Solved by deleting the bin and obj folders, which removed the reference with the blue icon. And after that reinstalled the NuGet packages, which added the references to the csproj file.
update-package -reinstall -project MyProjectName

Related

Missing file NuGet.targets on existing project

The scenario is:
1. Created a NEW solution
2. ENABLED download missing packages
3. Add projects to solution that already exists and depends on nuget packages
4. Building the solution generates an error:
... The missing file is <solution folder>\.nuget\NuGet.targets.
Why? Have missing something?
I'm using Visual Studio 2017 Pro on Windows 10
All my searches answer about the scenario where create a new solution and adds a new project that depends on nuget package, that's ok, but when have an existing project, nothing.
<solution folder>\.nuget\NuGet.targets is a file that NuGet's Visual Studio extension used to add in Visual Studio 2010, 2012 and 2013 when you right click on the solution and select "Enable NuGet Package Restore". It would then add an import in all of your project files to import the targets file. I was recently investigating a customer issue and as part of that investigation I found it made the following changes. Near the top of the csproj, it adds something like this:
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
and near the end of the csproj it adds somthing like this:
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
So, the problem is that you're creating a new solution, but using existing project files that have been modified in this way. One option is to edit your csrpoj files and remove these changes. Another option is to create new projects, in addition to the new solution, and then copy all your code and content files.
The only disadvantage is if you build on a CI server and use packages.config, your build script needs to run nuget.exe restore, whereas projects that use NuGet.targets could just build the solution and msbuild would execute nuget restore as needed. One advantage of no longer using NuGet.targets is that restoring the whole solution is faster than restoring project by project. Visual Studio automatically restores packages on build, even in VS2010, VS2012 and VS2013, so personally I discourage the use of using this feature, even if you use those old versions of Visual Studio. The benefit of reducing your build script by one step is not worth the issues it brings, in my opinion.

Nuget packages doubled

I have a visual studio solution with several projects all specifing their own packages.config.
If I run "nuget restore blablabla.sln", I get e.g. grpc.core\1.11.0 in my packages folder.
If I let Visual Studio do this I will get grpc.core\1.11.0 and Grpc.Core.1.11.0 in my packages folder both with the same contents!?
Why is that?
BR,
Daniel
Nuget packages doubled
According to your description, you should have more than two package resources in your Visual Studio with same nuget package grpc.core\Grpc.Core (Ignore case). As we know, nuget is not case sensitive when searching and restoring packages. So:
Double check the packages grpc.core\1.11.0 and Grpc.Core.1.11.0 are the same except capitalization.
Clean up your \packages folder before restoring the nuget from
Visual Studio.
If you confirm the above, please check if your package feed have the nuget package grpc.core\1.11.0. You can remove it, since it have the same contents as package Grpc.Core.1.11.0 in the default package source nuegt.org.
Hope this helps.

Unable to find nuget local source error occurred while restoring nuget packages the local source doesn't exist

I've been given a visual studio 2017 solution. When I open it fails as with the error:
Error occurred while restoring NuGet packages: The local source '\\network-location\' doesn't exist.
I can manually acquire a copy of these packages but I don’t know where this original path is configured and how I would go about changing it to the new location.
Any suggestions as to where I should look please?
The package sources can be found in the Visual Studio options (Tools -> Options) under NuGet Package Manager -> Package Sources or directly by clicking on the according icon in the NuGet dialog (context menu of a solution/project -> Manage NuGet Packages...):
Your local package source should then be listed in the following dialog:
The package source may, however, be solution or project specific and may therefore be specified in a NuGet.config file in the solution directory. Beginning with NuGet 3.4, Visual Studio looks in the project's directory or "or any folder up to the drive root", according to the NuGet.config reference. Up to NuGet 3.3, also subdirectories with the name .nuget where searched for NuGet.config files.
The file containing your local package source must be changed in order to restore the correct packages.
Nothing of the proposed solutions above did it for me. And, honestly, I really don't like, what Microsoft is doing for some time now: each time there's another surprise when installing an update. :-(
Analysis:
Error occurred while restoring NuGet packages: The local source 'C:\Microsoft\Xamarin\NuGet' doesn't exist.
Obviously NuGet is trying to restore from C:\\Microsoft\\Xamarin\\NuGet for s solution that has nothing to do with Xamarin. The solution compiled many times before and even getting it back from GIT did not change anything. So, the problem is not my solution. It is something more global.
By the way: I DONT WANT TO USE THIS FOLDER, cause I don't use Xamarin!
I found the following reference in the *.csproj.nuget.dgspec.json files in any obj folder of my solution. All these json files pointed to this Xamarin folder:
"fallbackFolders": {
"C:\\Microsoft\\Xamarin\\NuGet": {},
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
Question: How does VS know about the fallbackFolders?
I did not find any hint in any of my Visual Studio / NuGet configuration settings, as proposed above. I deleted all objfolder but each time when trying to compile or restore my packages, the reference came back.
The SOLUTION for me was :
delete all objfolders in your solution (as mentioned above)
delete c:\Program Files (x86)\NuGet\Config\Xamarin.Offline.config
There you will find the following:
<fallbackPackageFolders>
<add key="Xamarin Offline Packages" value="C:\Microsoft\Xamarin\NuGet\"/>
</fallbackPackageFolders>
This file was introduced on my machine one week ago, and I think it came with the latest VS update (16.2). I did not go away with the latest update (16.2.1) from today.
You will encounter the same issue in Visual Studio 2019. I have the same issue, I thought it was a conflict on Visual Studio 2017 but it wasn't.
The fix is you have to remove the source that is causing the issue.
You can remove it via Tools -> NuGet Package Manager -> Package Manager Settings
In my case i have getting this error:
Error occurred while restoring NuGet packages: The local source 'C:\Microsoft\Xamarin\NuGet' doesn't exist.
I have accidentally deleted 'C:\Microsoft\Xamarin\' folder.
After this VS2019 was not able to restore packages.
I just manually created 'C:\Microsoft\Xamarin\NuGet' folder.
Restarted VS, cleaned solution and everything goes well after this.
All answers are relevant however they are not complete, wasted 30 mins on this.
Below worked fine:
1 . Clear cache & remove issue folders:
Tools > NuGet Package Manager > Package Manager Settings
> NuGet Package Manager > General > Clear All NuGet Cache(s)
Tools > NuGet Package Manager > Package Manager Settings
> NuGet Package Manager > Package Sources
> Available package sources
> {uncheck the folder that is giving error}
> OK
2 . Restore NuGet Packages on VS Solution
Right-click on Visual studio solution (not project)
> Restore NuGet Packages
3 . Build & run project
Hope that helps.
I had this error in different situation. I checked contents of Nuget.config in my solution folder and under <packageSources> node it had an entry pointing to ./nuget. This folder didn't exist in the solution directory, so I just created an empty folder with this name and the solution compiled without any problems.
In My case the only way to solve it was to clean up all the NuGet cache(s).
You can find it at Tools -> NuGet Package Manager -> General
Clear All NuGet Cache(s) print
but I don’t know where this original path is configured and how I would go about changing it to the new location.
To resolve this error, please search the file NuGet.config in the given solution, then edit it with notepad, you will find following setting in that file:
<packageSources>
<add key="LocalServerName" value="\\network-location\" />
</packageSources>
You could change the value to the new location.
Same situation:
Error occurred while restoring NuGet packages: The local source 'C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages' doesn't exist.
My solution is re-creating the folder.

where does Nuget download packages when PackageReference is enabled

In visual studio 2017 i have enabled PackageReference so that package reference will be stored in csproj file instead of package.config file
I have added these 2 line in csproj file to enable PackageRefernce
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Now when i install any package using Nuget Package Manager, i see something like this
references with blue icon are added as package.
However i dont see any of these packages in packages folder under solution directory. Moreover, if i right click on blue icon (i.e reference) and click on properties, the window the blank. I cannot see the path where its referencing from
So when does Visual Studio download the packages when package? reference is enabled
looks like it installs the packages in %UserProfile%\.nuget\packages\
when packagereference in enabled

NuGet packages not restore in visual studio 2017

I have Asp.netCore solution which was working fine on Visual Studio 2015 and then i moved to Visual Studio 2017. Now the problem is that in Visual Studio 2017 on every nuget packages there is yellow exclamation mark. Following are solution which i have tried so far.
I'm using Visual Studio Version: 15.3.1
Run as 'Administrator' and restore package.
Clear All Nugget Cache(s) from Tools > options > NuGet Package Manager > and again restore Nuget.
Note: I have searched and found following solution and tried but did not resolve my issue.
Solution 1
I found the answer on another thread here and credit should go to #AxelWass although he did not specifically focus it towards this, it absolutely fixes this issue. The above answer did not.
I had the same issue and solve it by opening the project in a text editor and deleting the following section:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
</Target>
Once this is removed, it will resolve this nightmare issue that VS2017 and PM seems to be unable to resolve. I too have run into this multiple times - especially when I blend many projects in the same solutions directory.
As mentioned in Microsoft Installing and reinstalling packages with package restore Documentation, you should Update-Package -reinstall:
Update-Package -reinstall -ProjectName <project> command where
is the name of the affected project as it appears in
Solution Explorer. Use Update-Package -reinstall by itself to restore
all packages in the solution.
If you still have the error, try edit your project file, check if there is A path refrence error there, also check the project/solution nuget config file.
By default, new installation of visual studio did not configure package source to search packages online. That caused the problem.
I found the answer with a little bit more work from a stackoverflow link: https://stackoverflow.com/a/32360953/1503372.
That answer mentions to use "https://www.nuget.org/api/v2" url to restore packages. When I opened the package manager console in visual studio 2017, I found it was searching for packages from my PC only (offline search).
I then added "https://www.nuget.org/api/v2" url as a source for restoring packages and it worked.
Follow below steps to add a package source.
Right click project > Manage nuget package and you will see "package source label".
Add highlighted URL to package source.
Select "All" as package source.
Once you have configured your visual studio to search for packages online, your all packages will be restored.
I discovered a wrong configuration in the nuget.config. I don't know why, in this file there are some exclusion for my current project.
You can see your global configuration running this command in File Explorer
%AppData%\NuGet\NuGet.Config