How can I check the version of an assembly then delete the assembly?
- by Nescio
I am using the FileVersionInfo to retrieve the version of a .Net assembly.
Then, I want to immediately delete the file.
Unfortunately after I call GetVersionInfo, any attempt to delete the file results in an error “…in use by another process…”
Is there another technique to determine the version that does not lock the file?
Or, is it possible to ensure the lock is released after calling GetVersionInfo?
The below example is heavily simplified, but scope matches my real code.
void Main()
{
var fvi = GetVersion("myPath");
if (fvi.ToString() == "2.0.0.7")
DeleteFile("myPath");
}
FileVersionInfo GetVersion(string path)
{
return FileVersionInfo.GetVersionInfo(path);
}
void DeleteFile(string path)
{
File.Delete(path);
}