Visual Studio Could not find a part of the path system.net.http while checking in to TFS - visual-studio

I have a solution that compiles and runs fine. However when trying to check it in to TFS I get the error :
"Could not find a part of the path C:\pathToMyProjects\MyProject\packages\System.Net.Http.2.0.20126.16343\lib\net40\System.Net.Http.dll".
I recently installed Visual Studio 2017 while the project was last checked in to TFS while being built in Visual Studio 2015 if that has anything to do with it.
I've removed System.Net.Http from references and Nuget packages. Even when all are uninstalled I get the same error. Any clues as to how I can figure out what the real issue is?

The error you have is mainly caused when you're trying to check in files which is no longer exist on the machine.
This will happen when TFS has some changes staged that no longer exist
on the file system. For instance, if you add some files in Visual
Studio (which adds them to the changes list), delete them directly
from the file system, then attempt to check in the changes, it will
complain that it could not find the file(s).
Just try below things to narrow down the issue:
Check if the file exists under the the specific path mentioned in the
error message.
Go to Source Control Explorer -> select these nonexistent files
-> Undo Pending Changes. Or you can just left these files in the Excluded Changes list to not check in them.
Re-install/upgrade Nuget packages in Package Manager Console:
PM > update-package System.Net.Http -r
Uninstall the System.Net.Http Nuget packages and remove the reference, then reinstall the System.Net.Http Nuget packages and add the reference again.
Clean and rebuild your whole solution, once that compiles and runs
fine locally, then try to check in the changes again.
Check if this issue also occurs on other VS machines, so we could
know that whether it is related to the VS Environment or others.

Related

Nuget Update failure in Visual Studio 2019

I am having a strange (new) issue with Nuget in Visual Studio 2019 (v.16.9.0).
The Solutions are all ASP.NET Web Apps (MVC). I run on a local LAN. In the Nuget Package Manager 'Allow Nuget to download packages' and 'Automatically check for missing packages during build are both selected. I am using Packages.Config for management and the source is https://api.nuget.org/v3/index.json. VS is able to communicate via the Windows Defender Firewall. The target framework is .Net 4.7.2
The first issue is when I do a package restore after deleting the packages in the folder, it shows this error: The requested operation cannot be performed on a file with a user-mapped section open.
After I do the build, the files are being created correctly, including the new/existing DLLs. These replenished/refreshed DLLs work perfectly and the program runs. The strange part, however, is that the relevant NUPKG file has zero content (which is obviously triggering the error). The message eventually disappears after completion of the DLL downloads I assume. All good so far but with zero content in the NUPKG file.
When I now try to update a package things go awry, the Error List shows:
An error occurred while trying to restore packages. The file is not a valid nupkg. File path...
Then after a full restart of VS, I get this:
An error occurred while retrieving package metadata for 'ABC.3.5.0.2' from source 'I:....\packages'. 'ABC' being the first file in the package list. It therefore appears to be failing because the relevant NUPKG has no content.
I am able to paste any file freely to the packages folder and its sub-folders, indicating that there is no lock on the files. Also VS is able to write the rest of the package structure to the folder without issue.
IMHO this must mean that something is specifically locking/blocking the NUPKG files (or deleting their content during creation perhaps?). A search reveals nothing that I can see.
I even tried creating a brand new solution. During creation, the identical error message above popped up a warning. I also tried a few other of my existing solutions and got the same result. I updated VS and then I even did a full VS reinstall to the latest version, all to no avail.
I first noticed the issue after defining dependencies during an Azure Web App deployment (the Azure deployment tool optionally allows for updates to Nuget packages). After the Nuget update failed I set the option to blank and deployed anyway, the idea being to manually update the packages later. I cannot be certain, but I think this is when I discovered the issue. Could this process have changed a VS config setting somewhere perhaps?
Before the reinstall I opened the devenv.exe.config from inside VS and changed the IPV6 setting to false. No luck, so I have changed it back. I also did a test on one of the packages, downloading the package from the Nuget site directly and replacing the VS downloaded version, but I get the same errors.
Install failed. Rolling back... Package 'System.Buffers 4.5.1' does not exist in project 'ClickAuth_Graph' Package 'System.Buffers 4.4.0' already exists in folder 'I:\My Drive\Backups\ClickAuth_Graph (01_03_21)\packages' Added package 'System.Buffers 4.4.0' to 'packages.config' Removing package 'System.Buffers 4.5.1' from folder 'I:\My Drive\Backups\ClickAuth_Graph (01_03_21)\packages' This file is not a valid nupkg. File path...\packages\System.Buffers.4.5.1.nupkg Central Directory Corrupt An attempt was made to move the file pointer before the beginning of the file. At line:1 char 1 • Update-Package System.Buffers +CategoryInfo NotSpecified: (:) [Update-Package], Exception o FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.UpdatePackageCommand
For the record I have one stale Nuget package in the portfolio. I don't use Github, but a repository was set upfront. I have not recently committed anything to Github.
Is there an expert out there that can help?
What you described is in a mess. And please try the following suggestions:
1) first clean all nuget caches or delete all cache files under C:\Users\xxx\.nuget\packages and I:\My Drive\Backups\ClickAuth_Graph (01_03_21)\packages.
I think that you have download the valid nuget packages on it and if your local exists the same name,version nuget package, it will always use the local wrong nuget package. So you have to delete them and then download the right package from the nuget package source.
2) enter Tools-->Options-->Nuget Package Manager-->Package Sources and make sure that you have enabled nuget.org package source, and if you have other own feed which you want to use, also enable it.
If not, please try to close VS, delete nuget.config under C:\Users\xxx\AppData\Roaming\NuGet. And then restart VS to re-generate it. Then, re-add your own feed if you have it.
3) run update-package -reinstall under Tools-->Nuget Package Manager--> Package Manager Console and then also delete bin and obj folder of your project.
4) you could also try to disable Azure deployment tool
Besides, if you have other solution level nuget.config, please check whether its content is suitable for your project. And if it is useless, you could remove them.

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.

Error when rebuild the setup project in c#

Im getting below error when im going to rebuild my setup project in visual studio 2015.Please advice to resolve this:
The message means that the install of Visual Studio 2010 Shell (Integrated) is broken, so Windows is attempting to repair it. Also, it looks like it was installed from the internet, which resulted in the setup being performed from a temp folder that has since been deleted. It is always better to download the setup (such as the MSI file) and save it somewhere. It is also possible that the C:\Windows\installer folder has been damaged or has had files deleted because normally the repair would be performed from there, which might have been happening for a long time but you wouldn't have noticed until the cached MSI file was removed from /windows/installer.
The fix is to get hold of the exact same MSI file that was used to install VS 2010 Shell MSI file and save it somewhere, and browse to it when this happens again.
The cause might be a conflict between VS 2010 and VS 2015, or some removed or changed shared files. The application event log will have an MsiInstaller entry that says what is missing.

Visual Studio Online - Get Latest and NuGet

It's very possible that I'm missing something simple because I can't find others on the internet experiencing the same thing.
I'm a team that's new to the use of TFS and Visual Studio Online and we're encountering this problem:
(Using Visual Studio 2015 & 2013)
I used NuGet to add Microsoft.AspNet.WebApi.Cors to my newly created WebAPI project (ditto all other NuGet packages)
Did my work and checked in a building solution in to VSO
Co-worker did a Get Latest
His newly-retrieved project won't build and, when we expand the References, the assemblies are marked with a yellow warning icon, indicating that they're missing
We've tried (from the context of the failing project):
Update-Package
Update-Package -reinstall
Manually uninstalling and reinstalling the package in the NuGet UI
Manually adding the entire contents of the Packages directory in to TFS and doing a get latest on that directory as well
Wiping the solution out from his local file system and pulling it down clean
Copying the contents of my {Solution Directory}\Packages to a USB drive, walking it to my co-worker's computer, and copying it to his machine
Only item #6 worked but I'm CERTAIN that this cannot be the right answer.
I guarantee that this is worthy of a dope-slap but what might I be missing?
Thank you to jessehouwing for reminding me that this topic is still out here. He's exactly right on. We removed the Packages folder from source control and that resolved the problem completely.

Visual Studio + nuget + TFS: checking in nuget packages?

I'm working on a TFS project with a small team. This project has a bunch of nuget packages installed, but it's for a 4.0 project, and the nuget package manager GUI doesn't even offer the older versions of the packages any longer since their 4.5 equivalents are now being used. In order to allow other team members to compile the project, they need to have the exact versions of the packages. I'd like to check in the entire "packages" folder used by nuget. Is this a good idea? If so, how does one check in the "packages" folder and all its contents since it exists at the solution level? There is no "Include in Solution" option in Visual Studio as there is when you right-click an assembly.
in the past I have also checked in the NuGet packages into version control. With this some problems appeared:
Some packages where not checked into version control when committing from Visual Studio into TFS.
Updating packages became a real problem.
For the first problem I had used the TFS Power Tools. The problem with this solution is that every developer needed to install the Power Tools.
A better solution came up with NuGet 2.7. It introduced package restore. With package restore there's no need to check-in the packages folder. They will be restored during build.
We use an on-prem TFS install with no internet access so we have to check in our package folders or our builds fail. The biggest issue is that VS does not behave consistently when it comes to adding the pending changes for new package files, often times it will ignore the .dll files in the pending changes window, sometimes it adds everything fine.

Resources