Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, August 18, 2017 10:23 AM
Hi all,
I need to uninstall Nuget packages which unavailable in NuGet cache location. I have tried below command for uninstall NuGet packages. But, I get exception while uninstall NuGet packages which unavailable in NuGet cache location.
1.Use NuGet Package Manager Console
Uninstall-Package packageName
2.Use Nuget installer
installer.UninstallPackage(project, nuGetName, false);
3.Remove NuGet package entry and save ASP.NET Core project file. Then install same package another version, its show error like "Package restore failed. Rolling back package changes in projectName"
Please update any other commands for Uninstall Nuget packages which unavailable in Nuget cache location?
Please update If Its default behavior for Install/Uninstall NuGet packages.?
Thanks,
Dheeps
All replies (10)
Monday, August 21, 2017 5:49 AM
Hi Dheeps,
I'm install a nuget package in my project and then remove its local global cache. When I uninstall this package in my project, I don't get any errors.
In the output window, I found the uninstall process restore the package first which will re-download the package to local global path and then uninstall it.
So please check your Visual Studio settings to make sure it has enable Visual Studio download nuget packages when it missing.
Best Regards,
Weiwei
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].
Monday, August 21, 2017 11:55 AM
Hi,
-Thank you for your response.
We need to integrate logic programmatic for uninstall NuGet packages which unavailable packages in NuGet cache location.
We use installer for uninstall packages.
installer.UninstallPackage(project, nuGetName, false);
Please suggest any solution to uninstall NuGet packages which unavailable packages in NuGet cache location programmatic.
Tuesday, August 22, 2017 2:06 AM
Hi Dheeps,
Could you share some code snippet about your installer.UninstallPackage()?
According to the uninstall process, I suggest you add a try-catch block on installer.UninstallPackage(). When it throw "Package restore failed. Rolling back package changes in projectName" exception, you could execute the install action first and then uninstall it.
And you also could do check for local nuget repository path to make sure the package is located in that path. If it doesn't exist, please download and then uninstall.
Following sample provide install and clear package programmatically. Hope that could help you.
https://github.com/uluhonolulu/BlogSamples/tree/master/NuGetSample
Best Regards,
Weiwei
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].
Tuesday, August 22, 2017 3:48 AM
Hi @Weiwei,
Thank you for your response.
- I have uninstall Nuget package which unavailable in NuGet cache using below code I get error like package uninstall failed.
var installer = componentModel.GetService<IVsPackageUninstaller>();
installer.UninstallPackage(project, NuGetPackageName, false);
2. I have removed unavailable package entry from ASP.NET Core project and install same package with available version, it's show exception like Package restore failed. Rolling back package changes in projectName while try to install that package.
installer.installPackage(project, NuGetPackageName, false);
Can you please update if there's any solution to resolve this issue?
I need to uninstall NuGet packages which unavailable in NuGet cache location and install same NuGet package another version which available in NuGet cache location.
Its possible to uninstall Nuget package which unavailable in NuGet cache location programmatic?
Thanks,
Dheeps
Tuesday, August 22, 2017 8:53 AM
Hi Dheeps,
According to the NuGet API for Visual Studio, the IVsPackageInstaller interface only contains install method. The uninstall method contained in IVsPackageUninstaller interface.
/en-us/nuget/visual-studio-extensibility/nuget-api-in-visual-studio#ivspackageinstaller-interface
So please use IVsPackageInstaller interface to uninstall your packages.
If possible, please share a sample project to OneDrive to let us debug your code to check whethere there has any problem in your code.
Best Regards,
Weiwei
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].
Wednesday, August 23, 2017 5:00 AM
Hi,
Thank you for your response.
Issue 1: I have uninstall Nuget package which unavailable in NuGet cache using below code I get error like package uninstall failed.
var installer = componentModel.GetService<IVsPackageUninstaller>();
installer.UninstallPackage(project, NuGetPackageName, false);
Issue 1:
Install Nuget package in x.x.x version in ASP.NET Core project
Remove Nuget packages from Nuget cache location.
After that Uninstall that package form project using installer.
Issue 2: I have removed unavailable package entry from ASP.NET Core project and install same package with available version, it's show exception like Package restore failed. Rolling back package changes in projectName before try to install that package.
var installer = componentModel.GetService<IVsPackageInstaller>();
installer.installPackage(project, NuGetPackageName,false);
Issue2
Install Nuget package in x.x.x version in ASP.NET Core project
Remove Nuget packages from Nuget cache location.
Remove Nuget package entry from ASP.NET Core project file. Then save project and try to install same package with another version. it's show exception like "Package restore failed. Rolling back package changes in projectName"
Can you please update if there's any solution to resolve above issue?
I need to uninstall NuGet packages which unavailable in NuGet cache location and install same NuGet package another version which available in NuGet cache location.
Its possible to uninstall Nuget package which unavailable in NuGet cache location programmatic?
VS version (if appropriate): VS2010,VS2012,VS2013,VS2015
OS version : windows 10
Wednesday, August 23, 2017 8:40 AM
Hi Dheeps,
Does the "NuGet cache location" you mentioned is the local global path or the project packages path?
If it means the project packages path in project folder, we could not remove the unabailable package that not exist in this path. Because it needs to remove this package from this folder. If the package is not exist, the remove process will fail, which result the uninstall process failed.
If the NuGet cache location means the local global cache path, it will not effect the uninstall process when the package is not exist in this path. So it also doesn't have any effect when you try install another version of the package.
Best Regards,
Weiwei
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].
Tuesday, August 29, 2017 7:52 AM
Hi Dheeps,
Do you have any updates for this issue?
If any question for my explanation, please feel free to let me know.
Best Regards,
Weiwei
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].
Wednesday, August 30, 2017 4:38 AM
Hi @Weiwei,
-Thanks for you response.
Above you mentioned like " If Packages not available in local global cache path, it will not effect the uninstall process when the package is not exist in this path. So it also doesn't have any effect when you try install another version of the package."
I get exception "Package restore failed. Rolling back package changes in projectName" when I have tried in NuGet package Manager itself. Please refer below steps to reproduce exception.
1.Create Microsoft ASP.NET Core project with below combination in VS2017.
2.Install Bostrap 3.7.7 and Jquery 3.1.1 NuGet packages using NUGet package Manager.
3. Please unconfigured nuget.org in Nuget Package Manger.
4.Now delete Jquery and Boostrap packages from local NuGet cache.
5.Open NuGet package Manger . Jquery and Boostrap packages available in Installed category. Uninstall Boostrap packages 3.7.7
6.Please refer Package Manger console , Packages restored failed.
I have tried same process in Pragmatically using NuGet ApI in Visual Studio 2017. I have attached demo project (https://www.zeta-uploader.com/en/1552102660 ).Please refer below screenshot to demo project menu command.
Please refer below exception screenshot
Please update above mention issue default behavior for install/uninstall NuGet packages ?
If No, Please update workaround for resolve above issue.
Wednesday, August 30, 2017 8:02 AM | 1 vote
Hi Dheeps,
I reproduce your problem based on your detailed steps.
It should be default action for install/uninstall NuGet packages. Because when uninstall a package, it need to compare with the package cache to make sure what files need to be removed from project. If it is not cache in local machine, it will restore from nuget.org. But it is disabled in your situation.
So if the local package cache is missing, you need to make sure the package source is enabled, which could let the package restore successful and uninstall successful.
Best Regards,
Weiwei
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].