// ShadowCopyDemo.cs
namespace ShadowCopyDemo
{
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Threading;
sealed class ShadowCopyDemo
{
private readonly string _shadowCopyCachePath;
private readonly string _pluginDirectoryName;
private readonly string _pluginPath;
private readonly string _candidatesPath;
private bool _isVersion1;
private AppDomain _sandbox;
private PluginHost _pluginHost;
private readonly FileSystemWatcherEx _fsWatcher;
public ShadowCopyDemo()
{
this._shadowCopyCachePath = Path.Combine(
Environment.GetEnvironmentVariable("TEMP"),
Assembly.GetEntryAssembly().GetName().Name);
this._pluginDirectoryName = "Plugins";
this._isVersion1 = true;
this._pluginPath = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
this._pluginDirectoryName);
this._candidatesPath = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"Candidates");
this.GetSandboxAndHost(out this._sandbox, out this._pluginHost);
this._fsWatcher = new FileSystemWatcherEx(this._pluginPath, "*.dll");
this._fsWatcher.Changed += FileSystemWatcherOnChanged;
this._fsWatcher.EnableRaisingEvents = true;
}
public static void Main()
{
ShadowCopyDemo o = new ShadowCopyDemo();
o._pluginHost.LoadPlugins();
o._pluginHost.Invoke();
string cmd = ""
通过 AppDomain 的 ShadowCopying 功能实现 Assembly 的动态替换
最新推荐文章于 2023-05-06 10:21:41 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)