Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Force recompilation of C# file behind ASPX file

How do I force the recompilation of the C# file that powers an ASPX file?  I put gibberish on the top of the file and restarted the web service but it keeps on working.

If you can't tell I'm new at this and trying to make sense of somebody else's 100,000 line program!

Thomas David Baker
Wednesday, June 18, 2003

OK, I was being a dullard.  The C# is compiled to one DLL for the whole app and can only be "refreshed" through recompilation.  The days of fly-by-night web development are numbered.  I, for one, am not sure this is a good thing.

Thomas David Baker
Wednesday, June 18, 2003

Well actually you have a choice. You can put code that wil be (re)compiled on demand either in:
  <script runat=server language="C#">...</script>

or use the @Page src directive:
  <%@Page ... Src="someSourceCode.cs" %>

I prefer having our source code not deployed to customers - and just deploying the ASPXs and the DLL in the /bin folder.

Duncan Smart
Wednesday, June 18, 2003

Ah that's interesting.  Thanks very much.

Thomas David Baker
Thursday, June 19, 2003

OK so I've moved on a little here.  If I put Src="check_in.aspx.cs" in the Page directives I can mess up the C# file and I get a complication error.

However, when it successfully compiles I get an error that there is more than one source (its picking up the DLL too) for the code.

If I remove the Inherits attribute from the Page directives that error goes away but then the page seems to have lost its link with the C# file in some way and doesn't do what it was doing before (page loads fine but all the dynamic stuff and processing does not occur).

So I suppose my question is, how do I tell it not to talk to the DLL but still do the inherity dynamicy thing with the on-the-fly compiled .cs file?

If it helps my @Page tag is:

<%@ Page language="c#" Codebehind="check_in.aspx.cs" Inherits="globalband.check_in" AutoEventWireup="false" %>



Thomas David Baker
Thursday, June 19, 2003

The easiest thing is to change EVERY file to src= and simply remove the DLL. Now, you never need an explicit compilation step, because it's compiled by the system.

If you wanted to do 1 file at a time this way, then you'll need to change the build action of the files that should not be included in the DLL. Right click the file, click Properties, then under Advanced, change the Build Action to "None".

Brad Wilson (
Thursday, June 19, 2003

Thomas, first make sure that ALL of the "CodeBehind" attributes are changed to "Src" and then delete the web application's DLL from the bin directory so the runtime doesn't get confused deciding which type to load...

Alternatively you could go with the flow and get used to the code -> compile -> test cycle.

Ctrl+F5 is your friend (compile & run without debugging).

Duncan Smart
Thursday, June 19, 2003

*  Recent Topics

*  Fog Creek Home