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 (65)

  1. Justin says:

    This has been the only drawback for me using the Express editions. Thanks! This is what have been looking for … for a long time.

  2. Loris says:

    Excellent! I was quite disappointed when I found out that pre-compilation was not included inside VWD. No big deal, but compiling from the command line isn’t as nice as having it integrated inside the IDE.

    One small comment: on step 5 -v / ‘ should be instead -v / " (I mean, double quote instead of single)

  3. Jim Cheshire says:

    Thanks, Loris. I’ve corrected that typo.


  4. cielo says:

    i cannot execute the compiler. it says error 1010: ” is not a valid path.

    what shall i do?

  5. Jim Cheshire says:

    Hi, Cielo. You’ll need to double-check what you’ve done. Either you’ve done something wrong or there is a configuration problem.


  6. cielo says:

    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?

  7. Jim Cheshire says:


    That’s the purpose of this blog post. It walks you through automating the aspnet_compiler.exe to add a Build menu item.


  8. Ganesh says:

    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.

  9. Jim Cheshire says:

    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:


  10. Jac says:

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

  11. Jim Cheshire says:

    Do I win something if I guess right? 🙂

    There’s no way to say what’s wrong, Jac. I can try to help. Can you post what you have in the Arguments box?


  12. Jac says:


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


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


  13. Jim Cheshire says:


    Make sure that you include spaces in the right places. I suspect that’s your problem.


  14. Jac says:

    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 /


  15. Jim Cheshire says:

    Hi, Jac. Glad it’s working now. Thanks for the update.


  16. Sally says:

    Hi, when I run this my compiled directory appears but it is empty, my project doesn’t seem to have compiled. I do not get any error messages, just the utility message for the compiler, any ideas?


    command line: C:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_compiler.exe


    -p "$(ProjectDir)" -v / "$(ProjectDir)..Compiled" -u

  17. Mukul says:

    Thank you so much. This is exactly what I was looking for. You may want to also add line to specify -d for those who need pdb files generated for debugging.

  18. Przemek says:

    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.


  19. minikperi says:

    Good news

    Thank you for the informations.

  20. rod says:

    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


  21. Jim Cheshire says:


    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.


  22. rod says:

    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?


  23. Jim Cheshire says:

    Sounds to me like a host configuration issue, most likely that ASP.NET is not configured.


  24. rod says:


    You were right. My provider host configuration does not support ASP.NET

    Thank you vey much for your useful information about the automatic compiler



  25. Jim Cheshire says:

    Glad to help, Rod.


  26. n3llyb0y says:

    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"



  27. Cort says:

    I am having problem as Ganesh. When I click the browse button to browse to WindowsMicrosoft.NETFrameworkv2.0 etc. to get to the aspnet_compiler – the .NET framework is not there.

    Jim said to use the aspnet_compiler.exe in the v2.0.50727 but I don’t know how to get to v2.0. I’m using Visual Web 2008. I have 3.5 downloaded. I tried to download 2.0 – it says I already have it.

    How do I get to 2.0 from the command box?

  28. Jim Cheshire says:


    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:


    If you don’t, it means that either 2.0 isn’t installed or it’s installed incorrectly.


  29. cort says:

    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!

  30. Jim Cheshire says:


    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.


  31. Cort says:

    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

    Should I try another package? Should I just get rid of 3.5 and install 2.0?

    Thanks for hanging with me on this.

  32. Jim Cheshire says:


    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.


  33. cort says:

    Problem is fixed I believe.  I used the browse (…) button next to "Command’ as suggested and then went down to file in the next box I opened that and browsed to Microsoft Visual Studio 9.0Common7IDEVWDExpress.exe; that was my only choice. It was not what the book suggested but it seems to have worked; the pre-compiler tool is in my external tools menu.

  34. Jim Cheshire says:


    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.


  35. cort says:

    Oh boy, I’ve uninstalled .net framework 3.5 from my programs. Do I need to the delete the 3.5, 2.0, etc. files from my operating system?

    This is brand new computer – I don’t know how it got so screwed up so quickly.

  36. ersumanta says:

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

  37. Jim Cheshire says:

    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.


  38. Brian says:

    Hi Jim,

    Thanks for this article, I at least got everything compiled now.

    However when I upload the site to my host (goDaddy – virtual dedicated server). I receive error messages on the very first declaration line:

    Parser Error Message: Could not load the assembly ‘App_Web_oz-cehgn’. Make sure that it is compiled before accessing the page

    ‘App_Web_oz-cehgn.dll’ appears to have been created by the aspnet_compiler program.

    The file is sitting in my bin folder, but the message indicates that it cannot be read for whatever reason.

    When reading through some of their help stuff, I found the following in reference to a database publishing wizard "For security reasons, you cannot directly publish assemblies".

    Does this sound like a restriction of my provider? Shouldn’t the DLLs get picked up by the runtime simply because they’re in the bin folder?  Seems a bit pointless on goDaddy’s part to offer .NET hosting if you cannot drop assemblies into your own bin folder.

    Any advice of help is greatly appreciated. Thanks!


  39. Jim Cheshire says:


    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?


  40. Brian says:

    Here’s the whole output when I hit Default.aspx page. The page was designed with Web Developer 2008 Express, and the aspnet_compile from the .NET 2.0 framework folder.

    Server Error in ‘/’ Application.

    Parser Error

    Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

    Parser Error Message: Could not load the assembly ‘App_Web_erfxgq8o’. Make sure that it is compiled before accessing the page.

    Source Error:

    Line 1:  <%@ master language="C#" autoeventwireup="true" inherits="Fireside, App_Web_erfxgq8o" %>

    Line 2:  

    Line 3:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""&gt;

    Source File: /clients/fireside/Fireside.master    Line: 1

    Version Information: Microsoft .NET Framework Version:2.0.50727.1434; ASP.NET Version:2.0.50727.1434

  41. alex says:

    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.

  42. alex says:

    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?

  43. alex says:

    sorry for bothering you, I published!!!! it works perfect!!!!!! Thank you so much!!!!!!!!!!

  44. Jim Cheshire says:


    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.


  45. Jim Cheshire says:


    Thanks for the update. Glad to hear it’s working. 🙂


  46. Neamat says:

    I’m new to 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


  47. Jim Cheshire says:


    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.


  48. Edwin says:

    Thank you! This is a life saver!

  49. Norm Owen says:

    Just saw this aspnet_compiler article – I am going to try it out –

    Thanks for making it available to all.


  50. Martin says:

    I have the same problem as Sally – .

    The compiler runs, I get a few compile warnings variables defined and not used etc, the utput directory is created, but empty. Any ideas?

  51. JKapa says:

    Excellent, thank you very much!

  52. Tom Miller says:

    Can this customization be adapted to add a c sharp compiler command line to VWD?  If so, what environmental variables do I need to set?  Which copy of csc.exe (I have VWD 2008 with net 3.5 installed, their appear to be several copies of csc.exe)?

    I am working through a "Learning C#" book that assumes (and prefers) you have access to the command prompt compiler.  Its using the console to reduce the complexity of the exposition.  I am reluctant to install the C# express edition just for this functionality.

  53. Tom Miller says:

    I might be able to get the command line to work but it looks like I need to be able to create from a "console application template".  Sigh

  54. Jim Cheshire says:


    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.


  55. Jim Cheshire says:


    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.


  56. Kevin says:

    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?


  57. Jim Cheshire says:


    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.


  58. Jackie says:


    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.

  59. Jim Cheshire says:

    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.


  60. Jackie says:

    Thank you Jim, your reply was very quick.

    seems like after I redo the compile process a few more times, when I go on the same default page again, it shows an error:

    Could not load the assembly ‘App_Web_k9azrpdu’. Make sure that it is compiled before accessing the page.

    in which it highlights the line:

    <%@ page language="C#" autoeventwireup="true" inherits="_Default, App_Web_k9azrpdu" %>

    is the problem related to my code? because I rebuilt my code on local host and it worked fine.

  61. Jim Cheshire says:


    Without investigation, I can’t say what would cause that. As long as you use the command line I gave in my example, it should work fine. However, there are always things that can go wrong.

    If you continue to have trouble, it would be best to open a case with us to troubleshoot it with you.


  62. krishna says:


    I am a newbie and working with VWD and ASP.NET for the past couple of months.

    I worked on a web site and using the process suggested in this article, I created the Pre-compiler(non-updatable). This worked fine, thanks a lot for the detailed explanation.

    I applied the tool for my web site in VWD (Express 2008) and that created a new folder at the same level as the original. So far so good.

    Now I opened the ‘compiled folder’ in the VWD, previewed in brower and I stored the resulting web address in the ‘Add to Favorites’ folder.

    I closed the VWD and tried to open the web site through the stored web site address (in the Favorites folder). Well, it does not open.

    The error message is "The remote device or resource won’t accept the connection".

    I investigated further. When I open the ‘compiled web page’ in the VWD, the error appears to be on the source code:

    ‘<%@ page language="VB" masterpagefile="~/Clinic.master" autoeventwireup="false" inherits="_Default, App_Web_kq4wm2ir" title="Welcome to Bellevue Nephrology!" theme="Blue" %>’

    The explanation given when I pass my mouse over this line of code is the following:

    ‘Property "Profile" shadows an overloadable member declared in the base class "_Default’. If you want to overload the base method, this method must be declared "Overloads".’

    I have more than one web page in the application – ‘Default’ is the Home page and other pages like ‘Appointments’, ‘Schedules’ etc. In all the source code files, the same error as described above repeats.

    In the original web application, the code-behind file is the ‘_Default.aspx.vb’. This does not show in the ‘compiled’ form of the application.

    I guess that the problem is in the source code part:

    ‘inherits="_Default, App_Web_kq4wm2ir"’.

    I opened the above file in the System Browser and tried to look at the Profile attribute, but I cannot make out how to include the ‘Overloads’ for the method.

    I believe that I have a similar problem faced by Jackie (on October 2, 2009).

    Hi Jamesche, I hope that I have given enough details of the problem. Can you please suggest how I can sort it out?

    Thanks again for the great article.

    – Krishna

  63. Sameh Amin says:

    Thanks a lot my friend for this brilliant method for publishing my website, may Allah bless you…

  64. Dragan says:

    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.

  65. Cheapest Ipod says:

    Wow this is an awesome job. hope we see more and more blogs and attract more bloggers.GREAT advice, thank you!! ( :



    <a href=“”>Cheapest Ipodt</a>