Skip to content

Unnecessary exception being thrown #1547

@yishaigalatzer

Description

@yishaigalatzer

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)
            {
            }
        }

Metadata

Metadata

Labels

Priority:3Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog.Type:Bug

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions