1

I have added the ClientBuildManager.PrecompileApplicaiton to my Azure web role as described here. The web role will start, however, takes an extraordinary long time (15-20 mins), presumably from the amount of files it has to compile (18K+).

After the role starts, I hit the site, which doesn't appear to be any faster in initial startup.

When I RDP to my web role, I can see 2 separate folders in the Temporary ASP.NET Files, one containing all of my pre-compiled code (3K+ files), the other containing a smaller set of files matching those that would be used during my initial request (50 files).

From what I can tell, the site is pre-compiling, however, the actual requests are not leveraging this pre-compilation and doing a normal on-the-fly compilation as before when a request is made.

After viewing the above, I made another request to a different page within my site and confirmed the folder with 50 files increased to 58 files, telling me it is in fact still doing on-the-fly compiling. The other folder with 3K files remained unchanged.

Here is the code I am using for my pre-compilation in my OnStart method:

var siteName = RoleEnvironment.CurrentRoleInstance.Id + "_Web";
var mainSite = serverManager.Sites[siteName];
var rootVirtualPath = String.Format("/LM/W3SVC/{0}/ROOT/", mainSite.Id);
var clientBuildManager = new ClientBuildManager(rootVirtualPath, null);
clientBuildManager.PrecompileApplication();

Am I missing something else that would force the role to use my pre-compiled files?

Community
  • 1
  • 1
Bryan
  • 196
  • 5
  • 1
    Just as a followup, I also tried the following code for the pre-compilation, however, this failed in the Azure Emulator. foreach (var site in serverManager.Sites) { foreach (var app in site.Applications) { foreach (var dir in app.VirtualDirectories) { var clientBuildManager = new ClientBuildManager(dir.Path, dir.PhysicalPath); clientBuildManager.PrecompileApplication(); } } } – Bryan Sep 22 '15 at 14:50
  • I'd try supplying the second parameter to the `ClientBuildManager`'s constructor. And also trying out different constructors. https://msdn.microsoft.com/en-us/library/system.web.compilation.clientbuildmanager.clientbuildmanager(v=vs.110).aspx It seems that the IIS is unable to match the precompiled folder with your sources. – rocky Sep 28 '15 at 07:11

1 Answers1

0

Here's the full code that works, note one important difference is to NOT include trailing slash in appVirtualDir

   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