Hi,
I have a project that uses PostSharp. After build I have added another package. Then I tried to uninstall it and I got this error in console:
```
Uninstall-Package : The process cannot access the file 'path-to-packages\Libs.PostSharp-2.0.0.64\tools\PostSharp 2.0\Release\PostSharp.MSBuild.dll' because it is being used by another process.
At line:1 char:18
+ unInstall-Package <<<< NLog
+ CategoryInfo : NotSpecified: (:) [Uninstall-Package], IOException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.UninstallPackageCommand
```
I am playing with NuGet sources, so I was able to get the stack trace of the exception.
```
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.File.Create(String path)
at NuGet.PhysicalFileSystem.CreateFile(String path) in C:\projects\NuGet\nuget\src\Core\ProjectSystem\PhysicalFileSystem.cs:line 277
at NuGet.OptimizedZipPackage.EnsurePackageFiles() in C:\projects\NuGet\nuget\src\Core\Packages\OptimizedZipPackage.cs:line 236
at NuGet.OptimizedZipPackage.GetFilesBase() in C:\projects\NuGet\nuget\src\Core\Packages\OptimizedZipPackage.cs:line 139
at NuGet.LocalPackage.GetFiles() in C:\projects\NuGet\nuget\src\Core\Packages\LocalPackage.cs:line 198
at NuGet.PackageExtensions.GetFiles(IPackage package, String directory) in C:\projects\NuGet\nuget\src\Core\Extensions\PackageExtensions.cs:line 67
at NuGet.PackageExtensions.GetContentFiles(IPackage package) in C:\projects\NuGet\nuget\src\Core\Extensions\PackageExtensions.cs:line 72
at NuGet.ProjectManager.<RemovePackageReferenceFromProject>b__c(IPackage p) in C:\projects\NuGet\nuget\src\Core\ProjectManager.cs:line 376
at System.Linq.Enumerable.<SelectManyIterator>d__31`3.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.<ExceptIterator>d__99`1.MoveNext()
at System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at System.Linq.Enumerable.ToLookup[TSource,TKey](IEnumerable`1 source, Func`2 keySelector)
at NuGet.ProjectSystemExtensions.DeleteFiles(IProjectSystem project, IEnumerable`1 files, IEnumerable`1 otherPackages, IDictionary`2 fileTransformers) in C:\projects\NuGet\nuget\src\Core\Extensions\ProjectSystemExtensions.cs:line 124
at NuGet.ProjectManager.RemovePackageReferenceFromProject(IPackage package) in C:\projects\NuGet\nuget\src\Core\ProjectManager.cs:line 390
at NuGet.ProjectManager.Execute(PackageOperation operation) in C:\projects\NuGet\nuget\src\Core\ProjectManager.cs:line 174
at NuGet.ProjectManager.Execute(IPackage package, IPackageOperationResolver resolver) in C:\projects\NuGet\nuget\src\Core\ProjectManager.cs:line 145
at NuGet.ProjectManager.RemovePackageReference(IPackage package, Boolean forceRemove, Boolean removeDependencies) in C:\projects\NuGet\nuget\src\Core\ProjectManager.cs:line 340
at NuGet.ProjectManager.RemovePackageReference(String packageId, Boolean forceRemove, Boolean removeDependencies) in C:\projects\NuGet\nuget\src\Core\ProjectManager.cs:line 334
at NuGet.VisualStudio.VsPackageManager.<>c__DisplayClass40.<RemovePackageReference>b__3f() in C:\projects\NuGet\nuget\src\VisualStudio\VsPackageManager.cs:line 935
at NuGet.VisualStudio.VsPackageManager.RunProjectAction(IProjectManager projectManager, Action action) in C:\projects\NuGet\nuget\src\VisualStudio\VsPackageManager.cs:line 1263
at NuGet.VisualStudio.VsPackageManager.RemovePackageReference(IProjectManager projectManager, String packageId, Boolean forceRemove, Boolean removeDependencies) in C:\projects\NuGet\nuget\src\VisualStudio\VsPackageManager.cs:line 935
at NuGet.VisualStudio.VsPackageManager.UninstallPackage(IProjectManager projectManager, String packageId, SemanticVersion version, Boolean forceRemove, Boolean removeDependencies, ILogger logger) in C:\projects\NuGet\nuget\src\VisualStudio\VsPackageManager.cs:line 218
at NuGet.PowerShell.Commands.UninstallPackageCommand.ProcessRecordCore() in C:\projects\NuGet\nuget\src\VsConsole\PowerShellCmdlets\UninstallPackageCommand.cs:line 50
at NuGet.PowerShell.Commands.NuGetBaseCommand.ProcessRecord() in C:\projects\NuGet\nuget\src\VsConsole\PowerShellCmdlets\NuGetBaseCommand.cs:line 113
```
My question is why NuGet tries to create an existing file and why it is messing around files coming from a completely different package? The fact that PostSharp server is somehow keeping those files open should not fail the uninstallation process.
Thanks, Karel
Comments: Thanks for reporting. We believe we have fixed this issue in the latest build. Can you give it a try and let us know? http://build.nuget.org/nuget.tools.vsix
I have a project that uses PostSharp. After build I have added another package. Then I tried to uninstall it and I got this error in console:
```
Uninstall-Package : The process cannot access the file 'path-to-packages\Libs.PostSharp-2.0.0.64\tools\PostSharp 2.0\Release\PostSharp.MSBuild.dll' because it is being used by another process.
At line:1 char:18
+ unInstall-Package <<<< NLog
+ CategoryInfo : NotSpecified: (:) [Uninstall-Package], IOException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.UninstallPackageCommand
```
I am playing with NuGet sources, so I was able to get the stack trace of the exception.
```
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.File.Create(String path)
at NuGet.PhysicalFileSystem.CreateFile(String path) in C:\projects\NuGet\nuget\src\Core\ProjectSystem\PhysicalFileSystem.cs:line 277
at NuGet.OptimizedZipPackage.EnsurePackageFiles() in C:\projects\NuGet\nuget\src\Core\Packages\OptimizedZipPackage.cs:line 236
at NuGet.OptimizedZipPackage.GetFilesBase() in C:\projects\NuGet\nuget\src\Core\Packages\OptimizedZipPackage.cs:line 139
at NuGet.LocalPackage.GetFiles() in C:\projects\NuGet\nuget\src\Core\Packages\LocalPackage.cs:line 198
at NuGet.PackageExtensions.GetFiles(IPackage package, String directory) in C:\projects\NuGet\nuget\src\Core\Extensions\PackageExtensions.cs:line 67
at NuGet.PackageExtensions.GetContentFiles(IPackage package) in C:\projects\NuGet\nuget\src\Core\Extensions\PackageExtensions.cs:line 72
at NuGet.ProjectManager.<RemovePackageReferenceFromProject>b__c(IPackage p) in C:\projects\NuGet\nuget\src\Core\ProjectManager.cs:line 376
at System.Linq.Enumerable.<SelectManyIterator>d__31`3.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.<ExceptIterator>d__99`1.MoveNext()
at System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at System.Linq.Enumerable.ToLookup[TSource,TKey](IEnumerable`1 source, Func`2 keySelector)
at NuGet.ProjectSystemExtensions.DeleteFiles(IProjectSystem project, IEnumerable`1 files, IEnumerable`1 otherPackages, IDictionary`2 fileTransformers) in C:\projects\NuGet\nuget\src\Core\Extensions\ProjectSystemExtensions.cs:line 124
at NuGet.ProjectManager.RemovePackageReferenceFromProject(IPackage package) in C:\projects\NuGet\nuget\src\Core\ProjectManager.cs:line 390
at NuGet.ProjectManager.Execute(PackageOperation operation) in C:\projects\NuGet\nuget\src\Core\ProjectManager.cs:line 174
at NuGet.ProjectManager.Execute(IPackage package, IPackageOperationResolver resolver) in C:\projects\NuGet\nuget\src\Core\ProjectManager.cs:line 145
at NuGet.ProjectManager.RemovePackageReference(IPackage package, Boolean forceRemove, Boolean removeDependencies) in C:\projects\NuGet\nuget\src\Core\ProjectManager.cs:line 340
at NuGet.ProjectManager.RemovePackageReference(String packageId, Boolean forceRemove, Boolean removeDependencies) in C:\projects\NuGet\nuget\src\Core\ProjectManager.cs:line 334
at NuGet.VisualStudio.VsPackageManager.<>c__DisplayClass40.<RemovePackageReference>b__3f() in C:\projects\NuGet\nuget\src\VisualStudio\VsPackageManager.cs:line 935
at NuGet.VisualStudio.VsPackageManager.RunProjectAction(IProjectManager projectManager, Action action) in C:\projects\NuGet\nuget\src\VisualStudio\VsPackageManager.cs:line 1263
at NuGet.VisualStudio.VsPackageManager.RemovePackageReference(IProjectManager projectManager, String packageId, Boolean forceRemove, Boolean removeDependencies) in C:\projects\NuGet\nuget\src\VisualStudio\VsPackageManager.cs:line 935
at NuGet.VisualStudio.VsPackageManager.UninstallPackage(IProjectManager projectManager, String packageId, SemanticVersion version, Boolean forceRemove, Boolean removeDependencies, ILogger logger) in C:\projects\NuGet\nuget\src\VisualStudio\VsPackageManager.cs:line 218
at NuGet.PowerShell.Commands.UninstallPackageCommand.ProcessRecordCore() in C:\projects\NuGet\nuget\src\VsConsole\PowerShellCmdlets\UninstallPackageCommand.cs:line 50
at NuGet.PowerShell.Commands.NuGetBaseCommand.ProcessRecord() in C:\projects\NuGet\nuget\src\VsConsole\PowerShellCmdlets\NuGetBaseCommand.cs:line 113
```
My question is why NuGet tries to create an existing file and why it is messing around files coming from a completely different package? The fact that PostSharp server is somehow keeping those files open should not fail the uninstallation process.
Thanks, Karel
Comments: Thanks for reporting. We believe we have fixed this issue in the latest build. Can you give it a try and let us know? http://build.nuget.org/nuget.tools.vsix