[英]What is the equivalent of Assembly.GetEntryAssembly() in .NET Core?
In .net framework we could get the starting assembly using: 在.net框架中,我们可以使用以下命令获取起始组件:
Assembly.GetEntryAssembly();
But that is removed from .NET Core. 但是这已从.NET Core中删除。 Also there is no AppDomain. 此外,没有AppDomain。 How can I get access to the entry assembly in .NET Core and Windows Universal applications? 如何访问.NET Core和Windows Universal应用程序中的条目程序集?
(I need to find all of its embedded resource keys) (我需要找到所有嵌入式资源键)
Assembly.GetEntryAssembly()
is available in .NET Standard 1.5 , but not in versions 1.0 through 1.4. Assembly.GetEntryAssembly()
在.NET Standard 1.5中可用,但在1.0到1.4版本中不可用。 If you are only developing .NET Core and Universal Windows applications, version 1.5 should be sufficient for your needs. 如果您只开发.NET Core和Universal Windows应用程序,则1.5版本应该足以满足您的需求。
If I remember correctly, AppDomain
is destined to appear in .NET Standard 2.0 . 如果我没记错的话, AppDomain
注定会出现在.NET Standard 2.0中 。 It is not available now. 它现在不可用。
I ended up injecting the entry assembly into the library. 我最终将入口程序集注入库中。
In the library: 在图书馆:
class AssemblyHelper
{
// This can be called instead of Assembly.GetEntryAssembly()
public static Func<Assembly> GetEntryAssembly;
}
In the start-up application (which uses the library): 在启动应用程序(使用库)中:
class Program
{
public static void Main()
{
AssemblyHelper.GetEntryAssembly = () => typeof(Program).GetAssembly();
....
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.