我能够测试应用程序是否使用aspnet_compiler
构建的唯一方法是:
HttpRuntime.AppDomainAppId.EndsWith("_precompile")
然而,这感觉就像一个黑客。我可以检查配置数据库路径,但是可以通过切换到可执行文件轻松更改。有没有更健全,有文件证明的方法来确定这个?
答案 0 :(得分:0)
这是我提出的(虽然它仍然非常脏)。如果提供了更好的答案,我会将其更改为接受的答案。
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;
}