https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.ProjectManagement/Utility/MSBuildNuGetProjectSystemUtility.cs#L344
The second delete throws most of the time on the happy path. Not sure why this call is there to begin with, but we can definitely check if the directory doesn't exist before trying to delete it the first time.
msBuildNuGetProjectSystem.DeleteDirectory(path, recursive);
// Workaround for update-package TFS issue. If we're bound to TFS, do not try and delete directories.
var sourceControlManager = SourceControlUtility.GetSourceControlManager(msBuildNuGetProjectSystem.NuGetProjectContext);
if (sourceControlManager != null)
{
// Source control bound, do not delete
return;
}
try
{
Directory.Delete(fullPath, recursive);
// The directory is not guaranteed to be gone since there could be
// other open handles. Wait, up to half a second, until the directory is gone.
for (var i = 0; Directory.Exists(fullPath) && i < 5; ++i)
{
Thread.Sleep(100);
}
msBuildNuGetProjectSystem.RemoveFile(path);
msBuildNuGetProjectSystem.NuGetProjectContext.Log(MessageLevel.Debug, Strings.Debug_RemovedFolder, fullPath);
}
catch (DirectoryNotFoundException)
{
}
}
https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.ProjectManagement/Utility/MSBuildNuGetProjectSystemUtility.cs#L344
The second delete throws most of the time on the happy path. Not sure why this call is there to begin with, but we can definitely check if the directory doesn't exist before trying to delete it the first time.