[英]Release the lock on dlls picked up by MEF in a click once application
如何在我的ClickOnce应用程序(WPF)中启用此类插件dll可以在运行时进行删除?
我找到了一个旧的演示,用它做到这一点。
private static void SetShadowCopy()
{
AppDomain.CurrentDomain.SetShadowCopyFiles();
AppDomain.CurrentDomain.SetCachePath(@"C:\MEF\PartUpdatesInPlace\PartUpdatesInPlace\bin\Debug\Cache");
}
但是它会产生警告,它已经过时了,我应该使用别的东西,但我不知道如何在不做上述情况时启用阴影复制。 这两条线按预期工作。 我已经看到有人在做一个shell exe应用程序,它开始实际应用。 我也不想要那个。
我假设必须有一种方法与上面相同但不使用过时的方法。
// Works
AppDomain.CurrentDomain.SetShadowCopyFiles();
AppDomain.CurrentDomain.SetCachePath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Cache\");
// Dont Work
AppDomain.CurrentDomain.SetupInformation.ShadowCopyFiles = "true";
AppDomain.CurrentDomain.SetupInformation.CachePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Cache\";
区别似乎是SetShadowCopyFiles()从它被调用的点开始工作,所以当我在调用dll之后设置Mef目录时,我可以更新dll并执行container.refresh()而不会出现问题。
使用SetupInformation不会创建缓存文件夹并且dll会被锁定。
给别人。 到目前为止,这对于单击一次应用程序不起作用。
根据MSDN, SetShadowCopyFiles()的替代方案是IAppDomainSetup.ShadowCopyFiles {get; set;}
您应该只能将其设置为true
并提供相同的功能。
要使用它,请在SetupInformation上设置ShadowCopyFiles
属性。 AppDomain.ShadowCopyFiles
是只读的。
AppDomain.CurrentDomain.SetupInformation.ShadowCopyFiles = "true";
编辑:似乎在创建域后更改SetupInformation无效。
AppDomainSetup类:更改AppDomainSetup实例的属性不会影响任何现有的AppDomain。 当使用AppDomainSetup实例作为参数调用CreateDomain方法时,它只会影响新AppDomain的创建。
我不确定你现在应该怎么做,除了继续使用过时的方法,并担心.NET的下一次迭代可能会删除它们。
编辑2:我玩了一下这一点,并使用dotPeek看看AppDomain使用ShadowCopyFiles做了什么。 我决定看看我是否可以通过Reflection设置它。
您可能想尝试以下操作,看看这是否符合您的需要。 在AppDomain的内部FusionStore属性上将其设置为true会导致AppDomain.ShadowCopyFiles
属性反映在公开的SetupInformation.ShadowCopyFiles
属性上设置它时不是这种情况的更改。
var setupInfoProperty = AppDomain.CurrentDomain.GetType().GetProperty("FusionStore", BindingFlags.NonPublic | BindingFlags.GetProperty | BindingFlags.Instance);
var setupInfo = (AppDomainSetup) setupInfoProperty.GetValue(AppDomain.CurrentDomain);
setupInfo.ShadowCopyFiles = "true";
setupInfo.CachePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Cache\";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.