Cannot add Application Insights - Failed to install package 'Microsoft.Web.Infrastructure' - visual-studio

I try to monitor the memory usage of my CloudService and stumbled upon Application Insights.
When I try to add it I get following error message:
right click on WebProject -> Add Application Insights Telemetrik
Insert Subscription-Data -> click Add-Button
Now the error occurs when VS tries to install 'Microsoft.ApplicationInsights.Web.2.0.0'
We are using VS2015 and Windows 10
Edit:
The fun thing is I can install Microsoft.ApplicationInsights.Webversion 2.0.0 via the nuget-console. But when I afterwards try to add the ApplicationInsights again it throws the same error and the package-manager-console displays:
The package at \Path\To\Project\packages\Microsoft.Bcl.1.0.14 failed to uninstall. Restart Visual Studio to finish the process.

Things you can try:
close VS, and start it once as admin. You may have old auto-updated extensions, etc that haven't been cleaned up until you run as admin. then close that admin VS and go back to your normal non-admin VS.
clear out your nuget packages in your solution, and then doing a full re-build to ensure that all of the current packages in your project are correctly and fully installed. when we try to install the AI nuget packages programmatically, Nuget tries to validate all of the existing packages and sometimes something goes wrong there validating things that already installed
then try re-adding AI through the tool.
if you still get the error, look in the directory shown in the error message, and comment and let me know if (a) that folder exists at all and (b) if it does exist, what's in it?
If things are still failing, you should be able to add the Microsoft.ApplicationInsights.Web nuget package manually from nuget package manager, and after that is done, right click the "ApplicationInsights.config" file that was added by the nuget package install, and you should see a "configure application insights" option that will let you pick your account, subscription, and AI resource, and that will get updated in the config file for you. If none of that works, you can send me a mail to jgardner # microsoft and i can try to track down more details for you.
Edit to add: If you get this error about Microsoft.Bcl, then your project is probably targeting .NET 4.0 and this is probably an issue we just found today. hypothetically, if you manually install microsoft.bcl into the project first, then that specific error for that specific package should go away? (we're working on verifying this specific dependency and fixing this asap).

A simple Visual Studio restart fixed the issue for me.

Related

nuget dll is used by another process

I have the error from below and I'm quite out of ideas how to solve it. Tried the following until now:
Clean bin/obj/packages/packages cache
Remove manually from csproj and packages files the package and add it afterwards..still error
Update Visual Studio 2017
Reinstall Visual Studio 2017
Trace which processes are using a file with name that contains Newtonsoft
Copy the solution from another laptop where the builds works just fine
Yet, after all from above, I still get:
Error NuGet Package restore failed for project DriversApp.Android: Unable to find version '10.0.3' of package 'Newtonsoft.Json'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'Newtonsoft.Json.10.0.3' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.
https://api.nuget.org/v3/index.json: Error downloading 'Newtonsoft.Json.10.0.3' from 'https://api.nuget.org/v3-flatcontainer/newtonsoft.json/10.0.3/newtonsoft.json.10.0.3.nupkg'.
The process cannot access the file 'C:\Users\user\.nuget\packages\newtonsoft.json\10.0.3\lib\netstandard1.0\Newtonsoft.Json.dll' because it is being used by another process.
. Please see Error List window for detailed warnings and errors.
How to get this solved? I got really stuck on this one...
After a lot of investigation and ideas, I've solved this by uninstalling the antivirus solution as the rules added by me within my laptop were overrode by the company server policies.
As a conclusion, first check your antivirus solution, and if you are within a controlled environment, make sure your rules are not overrode by company server policies.
Thank you, #Leo Liu-MSFT for the assistance.
nuget dll is used by another process
You can try to use following troubleshooting to resolve this issue.
In Windows Explorer go to the folder where the NuGet packages are installed C:\Users\user\.nuget\packages, deleted the Newtonsoft.Json folders.
May it has something to do with the same package being referenced in multiple projects within the same solution, adding "-DisableParallelProcessing" to the nuget restore command, the final command would look like:
nuget restore "%WORKSPACE%\Solutions\App\App.sln" -DisableParallelProcessing
Excluding NuGet package files from the anti-malware products, or try to disable the antivirus. The anti-malware/antivirus products briefly locking these files during the NuGet restore operations.
Clear all referenced libraries before build the project by right click to Solution in solution explorer after click to "Clean Solution".
Most probably I was faced when there is some other error in the project (ie: project reference error etc.)
try 0: Remove all bin & obj from all project.
Try 1: Restart PC
Try 2: close vs & %temp% delete all
Try 3: Disable antivirus for the moment
Try 4: Change Debug to Release and revert back
Try 5: Clear All nuget caches
If above nothing works then shut down your pc, sit back for moments, relax and then check back.
Run this command with admin rights (net session /delete). It worked for me.

Nuget package install error -- Invalid URI: The Authority/Host could not be parsed

I'm using NuGet within Visual Studio 2017 to try to install a package on an older Web Forms project, and it is failing with the following error:
Invalid URI: The Authority/Host could not be parsed
This only happens when trying to install the package on a website that is mapped in IIS (other types of projects work fine), so the project name is http://localhost..., etc., which is what I think it's having trouble parsing. It worked fine until just a few days ago and I'm not sure what caused it to change. Here is the full message I am receiving:
Resolved actions to install package 'Newtonsoft.Json.10.0.3'
Found package 'Newtonsoft.Json 10.0.3' in 'd:\packages'.
Package 'Newtonsoft.Json.10.0.3' already exists in folder 'd:\packages'
Install failed. Rolling back...
Package 'Newtonsoft.Json.10.0.3' does not exist in project 'http://localhost:89/'
Executing nuget actions took 71.95 ms
Failed to add reference to 'Newtonsoft.Json'.
Invalid URI: The Authority/Host could not be parsed.
Another related clue is that when I open "Manage NuGet Pacakges..." on the website project, it is not showing anything as being installed, even though the packages.config file clearly exists in this project with several references defined.
My environment is as follows:
Visual Studio Professional 2107 Version 15.5.2,
Microsoft.NET Framework Version 4.7.02556,
NuGet Package Manager Version 4.5.0, and my NuGet repository is set to install in D:\packages
Does anyone have any advice on what setting I might be able to change to get this working again?
NuGet does not appear to be working for local IIS Web Site projects in VS 15.5.1 to 15.5.5 (inclusive).
The workaround is:
Close VS
(Just in case) make a backup copy of the .sln (solution file)
In a text editor open the .sln file and find the line:
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "http://www.devsite.com", "http://www.devsite.com", "{A8837508-9BC1-482A-86EF-4B3156CAFDBE}"
Amend the second parameter and save:
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "http://www.devsite.com", "DevWebsiteFolderName", "{A8837508-9BC1-482A-86EF-4B3156CAFDBE}"
Open your solution.
Use NuGet as you wish :-)
Optional:
Close VS
Reverse your .sln change.
Open VS
For credit and further reference:
NuGet fails for website projects hosted on local IIS
Nuget looking in wrong location for packages.config in web forms web site running on IIS
This was driving me nuts... I spent hours trying to install the Authorize.net nuget package in VS2017 and it kept throwing the same error.
I finally opened my project up in VS2015 and installed it without any issues.
Hope this helps.
Jason
Given that we haven't gotten any help from Microsoft on this, we've adopted the convention of doing something like what Barry Kaye suggested, but for the second parameter, just replacing it with a single period "."
This issue appears to be fixed in 15.6.0. Try upgrading to that version, if you can.
I encountered the same problem and I solve it this way:
Right-click on the project -> Properties -> Debug -> App URL
(The app URL was not the correct one)

How to restore NuGet packages for vs2015 project

I just built a new PC, installed my dev tools, connected to TFS and downloaded my project. Now most of my references are broken to EF, jQuery, etc.
The packages folder is missing all the .dlls, if I try to use NuGet restore nothing happens. If I use NuGet manager for Solution there is no "force" reinstall option.
NuGet seems to be more a hindrance than a help.
You can run "Update-Package -reinstall" command from Package Manager Console in VS to force reinstall all the packages.
Package authors often need to reinstall the same version of package
they are developing to test the behavior. The command Install-Package
does not provide ‘-force’ option, that could forcefully reinstall a
package. So, Update-Package -reinstall is added to meet that
requirement.
I've had that same issue plenty of times when I need to re-download code after getting a new PC. Here's what worked for me:
Download the project from TFS (or in your case SVN).
Delete the "packages" folder
Make sure the "Package Manager Console" is enabled (Tools -> NuGet Package Manager -> Package Manager Console)
Open the solution file.
At the right side of the "Package Manager Console," a "Restore" button should appear. Click on the "Restore" button.
Hope that helps you.
I'm not sure if I'm supposed to share the link if I already answered a similar question or just answer again, so I'm doing both. Here's the link to the same answer from a different asker.
Edit:
If after you complete the above steps you are still getting syntax errors from missing references, right-click on References in the Solution Explorer and then just hit OK. That fixed the problem with the references for me.

Nuget Package - feed (VSTS) :Exception 'System.AggregateException' thrown when trying to add source

I have created a new feed with in Package Release hub (VSTS), installed the credentials, then added the package source.
Now, I am using Visual Studio 2015 to install Micrososft.Aspnet.mvc to a project, however it gives the following error:
Exception 'System.AggregateException' thrown when trying to add source
'https://mysite.pkgs.visualstudio.com/DefaultCollection/_packaging/MyLogUtils/nuget/v3/index.json'.
Please verify all your online package sources are available.
I need to install NuGet packages normally, so I removed the feed from VSTS. However, the problem persists. How can this problem be resolved?
I met this issue today and fix it by following:
If you have delete the feed from VSTS, then you need to delete it from VS\Tools\Options\Nuget Package Manager\Package Sources:
If you didn't delete the feed in VSTS and want to use it, sign in with your VSTS team project account from VS upper right corner and restart VS:
This is may be an addition to the actual answer. I had to disable the check boxes as shown in below image to get the issue resolved. I think it might help to someone.
I had the same issue and I fixed issue by disabling my custom NuGet servers.
Go to Tools->Options->Nuget Package Manager and disable your custom NuGet servers
Since this is the first Page I hit with my Problem:
If you get the error for nuget.org site, increase Version number:
https://api.nuget.org/v3/index.json -> https://api.nuget.org/v4/index.json
under Tools->Options->Nuget Package Manager (see Image from #Eddie-MSFT)
V3 doesn't seem to work since today.
I also encountered that issue. I solved it by manually saving the index.json file and adding a local packaged source.
I had same issue, I resolved it by disabling its custom nuget server.
This exception might get when NuGet.Config file is readonly, for me unchecking the reaonly property of that file worked, generally, Nuget.config file exists in your project under .nuget folder.
File path project dir/.nuget/NuGet.Config
You have to ensure all your configured package source servers are available. Otherwise simply Go to Tools->Options->Nuget Package Manager and disable your custom NuGet servers.
One of the following might solve your problem.
Check and uncheck the package sources and click on update button, restart visual studio.
Uncheck all the other package source and only keep the one from nuget.org and click on update button, restart visual studio.
Once your package is install redo the changes as before.
'System.AggregateException' thrown when trying to add source 'https://devops.MyCompany.com/MC/_packaging/SharedFunctionalist/nuget/v3/index.json'. Please verify all your online package sources are available. One or more errors occurred.
Unable to load the service index for source https://devops.MyCompany.com/MC/_packaging/SharedFunctionalist/nuget/v3/index.json. Response status code does not indicate success: 401 (Unauthorized).
I got the same issue today.If you have noticed that It may asked you to enter DevOps credentials.That means it's request you to login your DevOps account.
There are two options for this type issue
1.Login with DevOps account(your Team Account) with your credentials.Then you can Install Nuget packages as usual.
2.Otherwise you have to delete existing package package source(which one is shared with team)by following below steps.
`Open Visual Studio ->Tools->Options->Nuget Package Manager-> Package Sources ->select that shared package Source and Delete it
Go to Tools->Options->Nuget Package Manager->Package Sources and uncheck the online NuGet Source named nuget.org https://api.nuget.org/v3/index.json. Also make sure your offline source is checked
I had the same problem. I resolved it by removing the checkmark from Tools/Options/Nuget Package Manager/Package Sources.
For me the package provoking the error was not showing up in the list of NuGet Sources (is it a bug?).
I had to go through the CLI (terminal) and enter
nuget sources
to get the list of Nuget sources.
Once the source causing the issue was listed I could remove it (you can also disable it)
nuget sources Remove -Name "source"
Documentation here
After that, restart Visual Studio

Error when trying to enable NuGet Package Restore in new Solution

I am getting an error when trying to enable package restore in a new solution I just created. The error in VS2012 is:
NuGet Package Manager
An error occurred while configuring the solution to restore NuGet
packages on build
Unable to read package from path 'NuGet.Build.2.7.0.npkg'.
I tried opening the solution in VS2010 to work around the problem and I am also getting an error when trying to enable package restore, but the message is different:
NuGet Package Manager
An error occurred while configuring the solution to restore NuGet
packages on build
Archive file cannot be size 0.
I tried creating a new solution, but got the same result.
I then tried doing a repair on VS2012 update 3 and rebooting. Still getting the problem.
I also scanned the folder, project, and solution file for anything NuGet or .nupkg, but there is nothing there.
So how can I get this feature working again? The last time I used it was about a week ago, and I don't remember specifically what I changed since then. I uninstalled the VS Power Tools package that I installed about a week ago, but that didn't fix the problem either.
Update
I followed the "removal" instructions here and used a project I already have as a template to enable package restore manually. However, I am still looking for a better solution because this is a feature I use frequently.
I also tried uninstalling and reinstalling NuGet from visual studio, but I still get the same issue. If memory serves correctly, there was a recent NuGet update (is there a log for VS extension installation so I can check?).
I suspect that the NuGet.Build.2.7.0.npkg file is zero bytes due to a failed download. NuGet.Build.2.7.0.npkg is the NuGet package that Visual Studio downloads in order to enable package restore for your solution.
Take a look in your cache and see if this file is zero bytes. If so then delete the file or clearing the cache and try enabling package restore again. The cache is under your profile in a directory similar to:
C:\Users\YourUsername\AppData\Local\NuGet\Cache
You can also browse to the cache from inside Visual Studio by opening the Package Manager Settings, selecting General and clicking the Browse button.
All of the previous answers, plus this one: can you run .\nuget\nuget.exe update -self if this is a solution in which package restore was previously enabled?
check whether your nuget package manager is updated one or not.
Check this from Tools-> Extensions and Updates -> Updates
Update your Nuget Package Manager and then it will work

Resources