简体   繁体   English

.NET Core中的Assembly.GetEntryAssembly()相当于什么?

[英]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.

相关问题 NUnit中的Assembly.GetEntryAssembly() - Assembly.GetEntryAssembly() in NUnit 使用Assembly.GetEntryAssembly()。Location来检测文件是否存在 - Using Assembly.GetEntryAssembly().Location to detect if file exists 我需要一个从不返回 null 的`Assembly.GetEntryAssembly()` 的替代方案 - I need an alternative to `Assembly.GetEntryAssembly()` that never returns null C#昂贵的方法调用? Assembly.GetEntryAssembly()和Assembly.GetCallingAssembly() - C# Expensive method calls ? Assembly.GetEntryAssembly() and Assembly.GetCallingAssembly() AppContext.BaseDirectory 与 Assembly.GetEntryAssembly().Location 在发布应用程序后是否相同? - AppContext.BaseDirectory vs Assembly.GetEntryAssembly().Location will be same after publishing the application? KerberosRequestorSecurityToken的.Net核心等效项是什么? - What is the .Net core equivalent of KerberosRequestorSecurityToken? IAuthenticationFilter 的 .NET Core 等价物是什么? - What is the .NET Core equivalent of IAuthenticationFilter? .Net Core中的.NET Framework ModelMetadataProvider相当于什么? - What is the equivalent of .NET Framework ModelMetadataProvider in .Net Core? .NET Core 中 [Serializable] 的等价物是什么? (转换项目) - What is the equivalent of [Serializable] in .NET Core ? (Conversion Projects) 与HttpRequestMessage等效的ASP.NET Core是什么? - What is the ASP.NET Core equivalent to HttpRequestMessage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM