How can I check the version of an assembly then delete the assembly?
Posted
by Nescio
on Stack Overflow
See other posts from Stack Overflow
or by Nescio
Published on 2010-05-14T12:02:00Z
Indexed on
2010/05/14
12:34 UTC
Read the original article
Hit count: 320
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);
}
© Stack Overflow or respective owner