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.

Published 27 September 07 02:39 by jamesche
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Justin said on October 26, 2007 9:09 AM:

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

# Loris said on October 26, 2007 9:50 AM:

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)

# jamesche said on October 26, 2007 10:23 AM:

Thanks, Loris. I've corrected that typo.

Jim

# cielo said on February 13, 2008 12:13 PM:

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

what shall i do?

# jamesche said on February 13, 2008 12:22 PM:

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

# cielo said on February 13, 2008 7:15 PM:

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?

# jamesche said on February 19, 2008 12:48 PM:

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

# Ganesh said on February 20, 2008 2:32 AM:

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.

# jamesche said on February 20, 2008 6:25 AM:

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

# Jac said on February 27, 2008 2:36 PM:

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

# jamesche said on February 27, 2008 2:43 PM:

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?

Jim

# Jac said on February 27, 2008 4:51 PM:

Non-updatable:

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

Updatable

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

Jac

# jamesche said on February 27, 2008 4:58 PM:

Jac,

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

Jim

# Jac said on February 28, 2008 9:06 AM:

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

# jamesche said on February 28, 2008 9:14 AM:

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

Jim

# Sally said on March 3, 2008 12:23 PM:

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?

thanks

command line: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe

arguments:

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

# Mukul said on March 5, 2008 4:47 PM:

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.

# Przemek said on April 5, 2008 12:52 PM:

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.

# minikperi said on May 1, 2008 11:13 AM:

Good news

Thank you for the informations.

# rod said on May 20, 2008 4:46 PM:

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

# jamesche said on May 20, 2008 4:55 PM:

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

# rod said on May 21, 2008 3:56 AM:

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

# jamesche said on May 21, 2008 8:45 AM:

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

Jim

# rod said on May 29, 2008 9:20 AM:

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

# jamesche said on May 29, 2008 9:51 AM:

Glad to help, Rod.

Jim

# n3llyb0y said on May 30, 2008 10:37 AM:

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

# Cort said on June 2, 2008 10:35 PM:

I am having problem as Ganesh. When I click the browse button to browse to Windows\Microsoft.NET\Framework\v2.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?

# jamesche said on June 3, 2008 9:10 AM:

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.NET\Framework\v2.0.50727

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

Jim

# cort said on June 4, 2008 12:11 PM:

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!

# jamesche said on June 5, 2008 9:32 AM:

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

# Cort said on June 5, 2008 11:14 AM:

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.

# jamesche said on June 5, 2008 11:17 AM:

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

# cort said on June 7, 2008 12:58 AM:

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.0\Common7\IDE\VWDExpress.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.

# jamesche said on June 7, 2008 9:11 AM:

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

# cort said on June 7, 2008 12:21 PM:

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.

# ersumanta said on June 13, 2008 7:50 AM:

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

# jamesche said on June 13, 2008 8:42 AM:

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

# Brian said on June 17, 2008 11:53 PM:

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!

  Brian

# jamesche said on June 17, 2008 11:59 PM:

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

# Brian said on June 18, 2008 9:17 AM:

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

# alex said on June 24, 2008 11:16 AM:

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.

# alex said on June 24, 2008 11:45 AM:

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?

# alex said on June 24, 2008 1:36 PM:

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

# jamesche said on June 26, 2008 10:34 AM:

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

# jamesche said on June 26, 2008 10:35 AM:

Alex,

Thanks for the update. Glad to hear it's working. :)

Jim

# Neamat said on July 29, 2008 2:11 PM:

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

# jamesche said on July 29, 2008 8:04 PM:

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

# Edwin said on September 24, 2008 3:22 AM:

Thank you! This is a life saver!

# Norm Owen said on October 18, 2008 6:36 PM:

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

Thanks for making it available to all.

Norm

# Martin said on February 27, 2009 12:16 PM:

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?

# JKapa said on May 21, 2009 11:19 AM:

Excellent, thank you very much!

# Tom Miller said on July 6, 2009 10:34 AM:

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.

# Tom Miller said on July 6, 2009 11:03 AM:

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

# jamesche said on July 6, 2009 3:52 PM:

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

# jamesche said on July 6, 2009 3:54 PM:

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

Leave a Comment

(required) 
(optional)
(required) 
Page view tracker