重命名和复制程序集安全吗?

时间:2021-04-01 19:30:46

I recently discovered that one can copy over an assembly that is in use by renaming the file and then performing the copy. E.G.

我最近发现,可以通过重命名文件并执行复制来复制正在使用的程序集。如

C:\Folder\MyLibrary.dll
=> rename to C:\Folder\MyLibrary.dll_old
=> copy new version C:\Folder\MyLibrary.dll (v2.0)

C:\ \ MyLibrary文件夹。dll =>重命名为C:\文件夹\MyLibrary。dll_old =>复制新版本C:\文件夹\MyLibrary。dll(v2.0)

I was told that the next time the application starts, it will loadup this new assembly. And while the application continues to run, it will continue to use the old assembly (even though it's renamed _old).

我被告知下一次应用程序启动时,它将加载这个新程序集。当应用程序继续运行时,它将继续使用旧程序集(即使它被重命名为_old)。

Seems like a hack to me. Is it safe to update assemblies in this manner?

对我来说,这似乎是个骗局。以这种方式更新程序集安全吗?

1 个解决方案

#1


3  

It is safe. As long as the old assembly stays loaded, the same app domain will not be attempting to load it again. The file name is not important for continued execution of the app.

它是安全的。只要旧程序集仍然被加载,相同的应用程序域就不会试图再次加载它。文件名对于应用程序的持续执行并不重要。

However, in production use you would probably have to think about 3+ simultaneous versions and a mechanism to remove the unused files eventually.

但是,在生产使用中,您可能需要考虑3+同步版本和一种机制,以便最终删除未使用的文件。

#1


3  

It is safe. As long as the old assembly stays loaded, the same app domain will not be attempting to load it again. The file name is not important for continued execution of the app.

它是安全的。只要旧程序集仍然被加载,相同的应用程序域就不会试图再次加载它。文件名对于应用程序的持续执行并不重要。

However, in production use you would probably have to think about 3+ simultaneous versions and a mechanism to remove the unused files eventually.

但是,在生产使用中,您可能需要考虑3+同步版本和一种机制,以便最终删除未使用的文件。