. net Core中与Assembly.GetEntryAssembly()等价的是什么?
本文关键字:是什么 Core 中与 Assembly GetEntryAssembly net | 更新日期: 2023-09-27 18:16:50
在。net框架中,我们可以使用:
Assembly.GetEntryAssembly();
但这是从。net Core中删除的。也没有AppDomain。如何访问。net Core和Windows Universal应用程序中的入口程序集?
(我需要找到所有嵌入的资源键)
Assembly.GetEntryAssembly()
在中可用。. NET Standard 1.5,但1.0到1.4版本中没有。如果你只开发。net Core和Universal Windows应用程序,版本1.5应该足以满足你的需求。
如果我没记错的话,AppDomain
注定会出现在中。. NET Standard 2.0。
我最终将入口程序集注入到库中。
库中:
class AssemblyHelper
{
// This can be called instead of Assembly.GetEntryAssembly()
public static Func<Assembly> GetEntryAssembly;
}
在启动应用程序中(使用库):
class Program
{
public static void Main()
{
AssemblyHelper.GetEntryAssembly = () => typeof(Program).GetAssembly();
....
}
}