简体   繁体   English

Azure starup任务中的aspnet_compiler

[英]aspnet_compiler in Azure starup task

Does anyone know if its possible to call aspnet_compiler from an azure role startup task to force a precompilation inplace. 有没有人知道是否可以从azure角色启动任务调用aspnet_compiler来强制进行预编译。 (And if so as a foregroudn/background or simple task?) (如果是foregroudn /背景或简单的任务?)

Perhaps something like: %windir%\\Microsoft.NET\\Framework64\\v4.0.30319\\aspnet_precompile.exe -v / -p "F:\\siteroot\\0" 也许类似于:%windir%\\ Microsoft.NET \\ Framework64 \\ v4.0.30319 \\ aspnet_precompile.exe -v / -p“F:\\ siteroot \\ 0”

Or are there any better ways to accomplish this? 或者有更好的方法来实现这一目标吗?

Yes, that should work once you figure out the right path to the compiler although I haven't tried this specific approach. 是的,一旦找到了编译器的正确路径,这应该可行,尽管我还没有尝试过这种特定的方法。

An alternative I've tried is to use ClientBuildManager.PrecompileApplication as described in this answer . 我尝试过的另一种方法是使用ClientBuildManager.PrecompileApplication ,如本答案中所述 I tried calling that from inside OnStart() but you can compile C# code as a .NET assembly and use that from PowerShell or just call .NET primitives from PowerShell as described here and that way call it from the startup task. 我打过电话,从里面OnStart()但你可以编译C#代码作为.NET程序集,并使用从PowerShell的或所描述的只是调用.NET元从PowerShell的位置和方式,从启动任务调用它。

A start-up task is possible, but one problem with that is that the siteroot path is hardcoded and that can change. 启动任务是可能的,但是其中一个问题是siteroot路径是硬编码的并且可以改变。 Instead add the following to the RoleEntryPoint OnStart method: 而是将以下内容添加到RoleEntryPoint OnStart方法:

 using (var serverManager = new ServerManager())
        {
            string siteName = RoleEnvironment.CurrentRoleInstance.Id + "_" + "Web";
            var siteId = serverManager.Sites[siteName].Id;
            var appVirtualDir = $"/LM/W3SVC/{siteId}/ROOT";  // Do not end this with a trailing /

            var clientBuildManager = new ClientBuildManager(appVirtualDir, null, null,
                                        new ClientBuildManagerParameter
                                        {
                                            PrecompilationFlags = PrecompilationFlags.Default,
                                        });

            clientBuildManager.PrecompileApplication();
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM