jmw
jmw

Reputation: 2864

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. (And if so as a foregroudn/background or simple task?)

Perhaps something like: %windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_precompile.exe -v / -p "F:\siteroot\0"

Or are there any better ways to accomplish this?

Upvotes: 3

Views: 619

Answers (2)

Mister Cook
Mister Cook

Reputation: 1602

A start-up task is possible, but one problem with that is that the siteroot path is hardcoded and that can change. Instead add the following to the RoleEntryPoint OnStart method:

 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();
        }

Upvotes: 0

sharptooth
sharptooth

Reputation: 170509

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. 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.

Upvotes: 2

Related Questions