[英]How to detect when application is being compiled with aspnet_compiler?
The only way that I've been able to test whether or not the application is being built with aspnet_compiler
is with the following: 我能够测试是否使用
aspnet_compiler
构建应用程序的唯一方法是以下方法:
HttpRuntime.AppDomainAppId.EndsWith("_precompile")
However, this feels like a hack. 但是,这感觉像是黑客。 I could check against the metabase path, however that can easily be changed with a switch to the executable.
我可以对照配置数据库路径进行检查,但是可以通过切换到可执行文件来轻松更改它。 Is there a more robust, documented way to determine this?
有没有更强大的文档记录方法来确定这一点?
Here is what I've come up with (though it's still quite dirty). 这是我想出的(尽管仍然很脏)。 If a better answer is provided, I change it to the accepted answer.
如果提供了更好的答案,我将其更改为接受的答案。
public static bool IsPerformingPrecompilation()
{
var simpleApplicationHost = Assembly.GetAssembly(typeof(HostingEnvironment))
.GetType("System.Web.Hosting.SimpleApplicationHost", throwOnError: true, ignoreCase: true);
return HostingEnvironment.InClientBuildManager &&
HostingEnvironment.ApplicationID.EndsWith("_precompile", StringComparison.InvariantCultureIgnoreCase) &&
HostingEnvironment.ApplicationHost.GetType() == simpleApplicationHost;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.