Del via


Automating aspnet_compiler in Visual Web Developer

Visual Studio has a cool user interface for publishing a website using the Publish Web Site dialog, accessible by selecting Build, Publish Web Site. You can use this dialog to pre-compile your website and avoid having to deploy source code.

Visual Web Developer Express doesn't offer this dialog, but because the Publish Web Site dialog is just a front-end for aspnet_compiler.exe, you can use aspnet_compiler.exe from a command prompt to accomplish the same thing if you are a VWD user. While using aspnet_compiler.exe from a command prompt gives you the same functionality, using a menu option is a lot more user-friendly and avoids possibly typos that can be frustrating.

In this post, I'm going to show you how you can add some menu options to VWD that will automate the user of aspnet_compiler. It won't give you the same flexibility and convenience you get with the full-blown Visual Studio, but it will come darn close.

Note: While I will show these steps in Visual Web Developer 2005 Express Edition, you can use the same steps for Visual Web Developer 2008 Express Edition.

To add the new menu item, I'll use the External Tools option on the Tools menu in VWD. (This menu option is also available in Visual Studio.) Using the External Tools dialog, you can add menu items that will execute external applications, and you can also control command line arguments that are passed to your external application and more.

Note: I also explain how to do this in my book, The Expression Web Developer's Guide to ASP.NET 3.5.

We'll create two menu items; one for pre-compiling an updatable application and another for a non-updatable application.

  1. Launch Visual Web Developer Express.
  2. Select Tools, External Tools to display the External Tools dialog.
  3. In the Title box, enter Pre-&Compile (non-updatable) .
  4. Click the browse button next to the Command box and browse to aspnet_compiler.exe located in c:\Windows\Microsoft.NET\Framework\v2.0.50727.
  5. Click Open to add the command line for aspnet_compiler.exe.

Now that you've got the correct command line for the aspnet_compiler.exe, it's time to add the arguments that will correctly pre-compile your application. This is where you'll see the true power of the External Tools dialog.

  1. Type -p " in the Arguments box. (That's an opening double-quote after the p.)
  2. Click the right-facing arrow next to the Arguments box and select Project Directory.
  3. Add a trailing double-quote to the Arguments box.
  4. Press the spacebar to add a space at the end of the existing arguments.
  5. Type -v / " after the space you just entered.
  6. Click the right-facing arrow next to the Arguments box and select Project Directory.
  7. Type \..\CompiledApp" after the existing arguments.

At this point, the Arguments box should contain the following:

-p "$(ProjectDir)" -v / "$(ProjectDir)\..\CompiledApp"

Now check the Close on Exit checkbox and click OK to add the new command to your Tools menu.

You can create another menu item that will compile the application and allow it to be updated by creating another entry using Pre-Co&mpile (updatable) as the Title and by appending -u to the arguments.

After you complete these steps, your pre-compiled application will be saved at the same level as your application's folder. For example, if your website exists in the c:\MyWebsites\WebApplication1, the pre-compiled application will be saved to c:\MyWebsites\CompiledApp. If that folder structure doesn't suit you, you can alter the steps above for your own purposes.

Comments

  • Anonymous
    October 26, 2007
    This has been the only drawback for me using the Express editions. Thanks! This is what have been looking for ... for a long time.

  • Anonymous
    October 26, 2007
    The comment has been removed

  • Anonymous
    October 26, 2007
    Thanks, Loris. I've corrected that typo. Jim

  • Anonymous
    February 13, 2008
    The comment has been removed

  • Anonymous
    February 13, 2008
    Hi, Cielo. You'll need to double-check what you've done. Either you've done something wrong or there is a configuration problem. Jim

  • Anonymous
    February 13, 2008
    thanks..i've check the project and it runs successfully but i cannot publish it on website...i'm using visual web developer 2008 express edition but there is no publish site option in the build menu..what are steps for me to publish it on website?

  • Anonymous
    February 19, 2008
    Cielo, That's the purpose of this blog post. It walks you through automating the aspnet_compiler.exe to add a Build menu item. Jim

  • Anonymous
    February 19, 2008
    Hi All, i have gone through all the post, but it doesnt work for the VWD 2008 users, because there is no any such  "aspnet_compiler.exe" in 3.5 framework folder. Please reply me if anybody has solution for this problem.

  • Anonymous
    February 19, 2008
    The 3.5 Framework is a supplement to the 2.0 Framework. The latest version of the CLR and ASP.NET binaries is 2.0. Therefore, you'll want to use the aspnet_compiler.exe in the v2.0.50727. For more information on versions, see my post here: http://blogs.msdn.com/jamesche/archive/2007/09/25/asp-net-version-madness.aspx Jim

  • Anonymous
    February 27, 2008
    After all the steps I tried to pre-compile. A short time the black window appeared on my screen, but there is no new folder for my pre-compiled application. What did I wrong???

  • Anonymous
    February 27, 2008
    The comment has been removed

  • Anonymous
    February 27, 2008
    Non-updatable: -p"$(ProjectDir)" -v/"$(ProjectDir)..CompiledApp" Updatable -p"$(ProjectDir)" -v/"$(ProjectDir)..CompiledApp" -u Jac

  • Anonymous
    February 27, 2008
    Jac, Make sure that you include spaces in the right places. I suspect that's your problem. Jim

  • Anonymous
    February 28, 2008
    Dear Jim, Thank you for your tips. Now everything goes well. I didn't know that I had to insert spaces after p, v and / Jac

  • Anonymous
    February 28, 2008
    Hi, Jac. Glad it's working now. Thanks for the update. Jim

  • Anonymous
    March 03, 2008
    The comment has been removed

  • Anonymous
    March 05, 2008
    The comment has been removed

  • Anonymous
    April 05, 2008
    Great article. This is what I was looking for. I also add "-f" option for automatically replacing existing folders. Now, I do not have to browse to the catalog and delete it. Thanks.

  • Anonymous
    May 01, 2008
    Good news Thank you for the informations.

  • Anonymous
    May 20, 2008
    hi jamesche, thank you very much for your useful information, great! as Cielo the project runs successfully and I got the compile folder, perfect, but when I publish on website I got this message in a blank page "This is a marker file generated by the precompilation tool, and should not be deleted!" is any other step to follow in order to publish in a website? give me a clue please rod

  • Anonymous
    May 20, 2008
    Rod, If you precompile without the option of making the site updatable, all of the code in the .aspx pages themselves will be compiled into your assemblies and replace with the placeholder text that you reference. When a request is made for one of those pages, ASP.NET will actually render the page from the assembly that you pre-compiled. It sounds to me like either you didn't deploy your assemblies or that your hosting company has something misconfigured. I don't think it's the former because I suspect you would get an error telling you that the type couldn't be found if that were the case. Jim

  • Anonymous
    May 20, 2008
    ok, Thank you, Jim for the help... now I did compile with the option of making the site updatable. The folder is created and I transfered it through FileZilla to the host server in the browser I got only the code of the default.aspx "<%@ page masterpagefile="~/MasterPage.master" language="C#" autoeventwireup="true" ...etc" any clue? rod rodgeck@hotmail.com

  • Anonymous
    May 21, 2008
    Sounds to me like a host configuration issue, most likely that ASP.NET is not configured. Jim

  • Anonymous
    May 29, 2008
    Jim You were right. My provider host configuration does not support ASP.NET Thank you vey much for your useful information about the automatic compiler Rgds, rod

  • Anonymous
    May 29, 2008
    Glad to help, Rod. Jim

  • Anonymous
    May 30, 2008
    James - great info. thank you very much. For my own environment I had to specify alternate source/target directory under the guise of $(ItemDir). I think some other people may run into this (those just getting a short black command window appear then nothing). -p "$(ItemDir)" -v / "$(ItemDir)..CompiledApp" Cheers, n

  • Anonymous
    June 02, 2008
    The comment has been removed

  • Anonymous
    June 03, 2008
    Cort, I believe you emailed me from my website. I replied to you, but I never heard back. I take it you are at the same point with your problem. You should have a copy of aspnet_compiler.exe in the following folder: %windir%Microsoft.NETFrameworkv2.0.50727 If you don't, it means that either 2.0 isn't installed or it's installed incorrectly. Jim

  • Anonymous
    June 04, 2008
    Hi Jim, I did reply - not sure what happened - but perhaps its for the best - my answer had little reference to the problem. I have downloaded .NET 3.5 again and have searched and searched for the file (using Search) and looking in operating system and other files but have been unable to find the file. I can find  this file v2.0.50727 but when I open the folder there's nothing in it. Sorry about the trouble - I am a real novice!

  • Anonymous
    June 05, 2008
    Cort, The 3.5 Framework cannot stand on its own. It builds upon the 2.0 Framework. Therefore, in order to use the 3.5 Framework, you also need to have the 2.0 Framework installed. If you have nothing in the v2.0.50727 folder, that tells me that you don't have the 2.0 Framework installed. I would first try installing that and see if it resolves your problem. Jim

  • Anonymous
    June 05, 2008
    Thanks Jim as I stated in my first e-mail when I try to install 2.0 I get an error message stating 'error product already installed'. I'm trying to download the version 2.0 redistributable package http://www.microsoft.com/downloads/thankyou.aspx?familyId=0856eacb-4362-4b0d-8edd-aab15c5e04f5&displayLang=en Should I try another package? Should I just get rid of 3.5 and install 2.0? Thanks for hanging with me on this.

  • Anonymous
    June 05, 2008
    Cort, I suspect that your install of the 2.0 Framework is corrupt. I would uninstall it and reinstall it to see if that resolves it. Jim

  • Anonymous
    June 06, 2008
    The comment has been removed

  • Anonymous
    June 07, 2008
    Cort, If you follow these steps, you will have a menu entry for pre-compilation, but when you click it, it's going to run VWDExpress.exe. That's not going to work and likely will generate an error. In order for this to work, you must select the aspnet_compiler.exe. To add to that, it's important to note that if the 2.0 Framework isn't properly installed, you can't run ASP.NET 3.5 or 2.0. Jim

  • Anonymous
    June 07, 2008
    The comment has been removed

  • Anonymous
    June 12, 2008
    Can any one please tell me what is the EQUIVALENT for aspnet_compiler.exe in .NET 3.5 .. In case I need to do the entire process using compiler of .net 3.5 .. i am not able to locate aspnet_compiler.exe in .net 3.5 folder  ..

  • Anonymous
    June 13, 2008
    Hi, Ersumanta. There isn't a new version of aspnet_compiler.exe for the 3.5 Framework. The latest version is the 2.0 version. Jim

  • Anonymous
    June 17, 2008
    The comment has been removed

  • Anonymous
    June 17, 2008
    Brian, There can be many reasons why an assembly fails to load. However, what you are seeing looks like it might not be finding the assembly at all. You'll need to check with GoDaddy to be sure what's happening, but I'd check that they are running the right version of ASP.NET as well. Was there any additional information on the error page? Jim

  • Anonymous
    June 18, 2008
    The comment has been removed

  • Anonymous
    June 24, 2008
    please, I am really new and don't know how publish web site. Your explanation is clear, now I have folder CompiledApp on my disk C. But how I can publish it on my domain name.

  • Anonymous
    June 24, 2008
    please, I am really new and don't know how publish web site. Your explanation is clear, now I have folder CompiledApp on my disk C. But how I can publish it on my domain name. my hosting says : " you should not have compiled files behind your domain name folder. " how I can compile it in my domain folder?

  • Anonymous
    June 24, 2008
    sorry for bothering you, I published!!!! it works perfect!!!!!! Thank you so much!!!!!!!!!!

  • Anonymous
    June 26, 2008
    Brian, That should work as long as the assembly has been deployed to the server. If it doesn't, it's impossible to say why without getting some more detailed information from the hosting company and troubleshooting it. Jim

  • Anonymous
    June 26, 2008
    Alex, Thanks for the update. Glad to hear it's working. :) Jim

  • Anonymous
    July 29, 2008
    I'm new to Asp.net and I found that your automation for the publish button is very useful but I compiled the website and I got it compiled and what i wanted to do is to use it with the IIS available in my machine. I have this error as a result: Server Application Unavailable The web application you are attempting to access on this web server is currently unavailable.  Please hit the "Refresh" button in your web browser to retry your request. I don't know what to do exactly and at the same time I want to upload it to another server but I need to be sure first that it's working on the IIS. Can you tell me what should I do exactly? .. Thank you so much Neamat

  • Anonymous
    July 29, 2008
    Neamat, That error can be caused by any number of things. It may not even be related to ASP.NET. I'm afraid that there's not enough information here to help you. My suggestion is that you contact our product support and open a case to investigate this further. Jim

  • Anonymous
    September 23, 2008
    Thank you! This is a life saver!

  • Anonymous
    October 18, 2008
    Just saw this aspnet_compiler article - I am going to try it out - Thanks for making it available to all. Norm

  • Anonymous
    February 27, 2009
    I have the same problem as Sally - http://blogs.msdn.com/jamesche/archive/2007/09/27/automating-aspnet-compiler-in-visual-web-developer.aspx#8006229 . The compiler runs, I get a few compile warnings variables defined and not used etc, the utput directory is created, but empty. Any ideas?

  • Anonymous
    May 21, 2009
    Excellent, thank you very much!

  • Anonymous
    July 06, 2009
    The comment has been removed

  • Anonymous
    July 06, 2009
    The comment has been removed

  • Anonymous
    July 06, 2009
    Martin, If the directory is empty, it's because the compile didn't succeed. I would look into the errors you say you are seeing and fix them. Jim

  • Anonymous
    July 06, 2009
    Tom, I'm not sure what you're asking. This article is designed to teach you how to replicate the behavior in VS's Publish Web Site dialog inside of VWD. Jim

  • Anonymous
    September 09, 2009
    I am not understanding the ", App_Web_..." part of the publish. I am trying to publish a web site and then move a couple of the compiled web files to production site. Is there something I need to do in configuration to make this happen? Thnx

  • Anonymous
    September 09, 2009
    Kevin, The App_Web assemblies contain the code that was pre-compiled by the publish process. The number of these that you'll have depends upon whether or not you are using fixed names in the publish dialog. Typically, the Publish process compiles the site and deploys the site. In other words, the destination for the publish is the location of your site. If you want to deploy manually, you need to copy over the /bin folder, the .aspx files, and any other supporting files/folders specific to your app like .config files, app_data, etc. Jim

  • Anonymous
    October 02, 2009
    Hi, Thanks for the tutorial about the compiler awsome! though i do need some more assistance.. i have it compiled fine.. it generated the CompileApp folder and there is stuff inside it. I put those files on the webserver, and I opened the MySite/Default.aspx page and it just says: "This is a marker file generated by the precompilation tool, and should not be deleted!" I don't really know how I can have my website to show. Thank you for the help in advance.

  • Anonymous
    October 02, 2009
    Hi, Jackie. That will happen if you specify the switch to now make the site updatable. In that case, all of the code for your pages is contained within the compiled DLLs and the .aspx pages are there only so that the web server sees a file. Jim

  • Anonymous
    October 02, 2009
    The comment has been removed

  • Anonymous
    October 02, 2009
    The comment has been removed

  • Anonymous
    December 27, 2009
    The comment has been removed

  • Anonymous
    August 18, 2010
    Thanks a lot my friend for this brilliant method for publishing my website, may Allah bless you...

  • Anonymous
    December 07, 2010
    Thank you for this amazing post. I'm hosting a website for the first time, and I want everything to be legal since I have no money to buy VS licence. This advice makes precompiling the site in VWD 2010 hassle free.

  • Anonymous
    May 17, 2011
    The comment has been removed