仔细对比1.x和2.0的源码后发现方法:
protected virtual IEnumerable<Assembly> SelectAssemblies()
BootstrapperBase 发生了一些变化。
// Decompiled with JetBrains decompiler
// Type: Caliburn.Micro.BootstrapperBase
// Assembly: Caliburn.Micro, Version=1.5.2.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f
// MVID: DC6F950D-BBB2-4CAB-9754-D5C81FE2659F
// Assembly location: ..\bin\Debug\Caliburn.Micro.dll
if (Execute.InDesignMode)
{
AppDomain currentDomain = AppDomain.CurrentDomain;
Assembly assembly = Enumerable.LastOrDefault<Assembly>((IEnumerable<Assembly>) (currentDomain.GetType().GetMethod("GetAssemblies").Invoke((object) currentDomain, (object[]) null) as Assembly[] ?? new Assembly[0]), new Func<Assembly, bool>(BootstrapperBase.ContainsApplicationClass));
if (assembly == (Assembly) null)
return (IEnumerable<Assembly>) new Assembly[0];
return (IEnumerable<Assembly>) new Assembly[1]
{
assembly
};
}
else
{
Assembly entryAssembly = Assembly.GetEntryAssembly();
if (entryAssembly == (Assembly) null)
return (IEnumerable<Assembly>) new Assembly[0];
return (IEnumerable<Assembly>) new Assembly[1]
{
entryAssembly
};
}
而对于 2.0 (Bootstrapper.cs):
/// <summary>
/// Inherit from this class in order to customize the configuration of the framework.
/// </summary>
public abstract class BootstrapperBase {
... left out for brevity
/// <summary>
/// Override to tell the framework where to find assemblies to inspect for views, etc.
/// </summary>
/// <returns>A list of assemblies to inspect.</returns>
protected virtual IEnumerable<Assembly> SelectAssemblies() {
return new[] { GetType().Assembly };
}
我遇到了这个问题,因为我依靠 SelectAssemblies() 的能力将可执行程序集返回给我以供下游使用。
我可以通过这样覆盖来解决问题(出于我的目的,我需要 exe 程序集):
protected override IEnumerable<System.Reflection.Assembly> SelectAssemblies()
{
return new[] { Assembly.GetEntryAssembly() };
}
欢迎了解 CB.M 团队为何更改此方法的人士发表评论。