3

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?

jmw
  • 2,864
  • 5
  • 27
  • 32

2 Answers2

2

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.

Community
  • 1
  • 1
sharptooth
  • 167,383
  • 100
  • 513
  • 979
  • 1
    The ClientBuildManager.PrecompileApplication sound like a nice way to do it. When calling it from on start what constructor args did you specify for the ClientBuildManager? I am not quite sure how I should get a hold of the corrects paths. – jmw Apr 09 '13 at 14:01
  • 1
    @JWendel: You can use `Microsoft.Web.Administration.ServerManager`, enumerate all `Sites`, for each of them enumerate all `Applications`, for each of them - all `VirtualDirectories` and each of those has `Path` and `PhysicalPath` - those two you can pass into `ClientBuildManager` construtor. – sharptooth Apr 09 '13 at 14:18
  • Great thanks! Going to try it out. For others looking for the Microsoft.Web.Administration its available as a NuGet package - http://nuget.org/packages/Microsoft.Web.Administration/. – jmw Apr 09 '13 at 14:26
0

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();
        }
Mister Cook
  • 1,552
  • 1
  • 13
  • 26