i am running in an exception when I want to update extensions in Visual Studio 2015. Each and every time I am updating an extension I will get an file is already in use exception. I tracked this down to the file *.pkgdef.
I am running in this exception on my working pc only. This machine runs Windows 8.1 with McAfee Antivirus, Firewall and Drive Encryption. I have the feeling that drive encryption has something to do with this exception but I can not say this for sure.
I debugged VSIXInstaller and found something that I believe is a bug. The class is ExtensionManagerService.cs in the assembly Microsoft.VisualStudio.ExtensionManager.Implementation.dll .
private void AtomicallyDeleteFiles(IEnumerable<string> filePaths, bool justMarkForDeletion)
{
foreach (FileStream fileStream in this.LockFiles(filePaths, (IList<string>) null))
{
if (justMarkForDeletion)
{
string str = fileStream.Name + ".deleteme";
File.Delete(str);
File.Move(fileStream.Name, str);
}
else
File.Delete(fileStream.Name);
fileStream.Close();
}
}
The LockFiles method is implemented as followed:
private IEnumerable<FileStream> LockFiles(IEnumerable<string> filePaths, IList<string> inUse = null)
{
List<FileStream> list = new List<FileStream>();
foreach (string path in filePaths)
{
try
{
FileAttributes attributes = File.GetAttributes(path);
if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
{
FileAttributes fileAttributes = attributes & ~FileAttributes.ReadOnly;
File.SetAttributes(path, fileAttributes);
}
FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Write, FileShare.Delete);
list.Add(fileStream);
}
catch (Exception ex)
{
if (ex is FileNotFoundException)
{
try
{
Registry.SetValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\VisualStudio\\Extensibility\\ExtensionSDKDeletionListStore\\", "ScanForDeleteMeExtensionSDKsAtStartup", (object) 1, RegistryValueKind.DWord);
Registry.SetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\Extensibility\\ExtensionSDKDeletionListStore\\", "ScanForDeleteMeExtensionSDKsAtStartup", (object) 1, RegistryValueKind.DWord);
}
catch
{
}
}
if (inUse == null)
{
foreach (Stream stream in list)
stream.Close();
throw;
}
else
inUse.Add(path);
}
}
return (IEnumerable<FileStream>) list;
}
The exception happens at File.Move in AtomicallyDeleteFiles. I think that at that point a File.Copy was intended to be used. The file can not be moved because it was locked in the first place.
What I could not determine is why this only happens on my McAfee machine. But this problem was reported also here Can't Update or Uninstall NuGet Package Manager in VS2012 and here http://www.paraesthesia.com/archive/2013/07/30/upgrading-nuget-the-process-cannot-access-the-file-because-it.aspx/.
I do not know how can I get in touch with the Visual Studio Team. Would you consider this a bug too ? Can anyone help me reporting this ?
Regards T4E