Link to home
Start Free TrialLog in
Avatar of muaddib2004
muaddib2004

asked on

ASP .NET - Updating one C# code-behind file in production

Greetings,

I have an ASP .NET web application residing on an production server. If the need arouse to make modifications to one particular C# code behind file; I would not fathom having to recompile my current development version and re-deploying the entire application to the production server (due to the possibility of having untested code currently in development..)

So I would like to know what would be the best way to update my production application if it just involved a minor change to one particular C# file?  I mean, I couldn't just copy the file over.. the entire application would have to be re-complied on the production server, right?  What is the best way to do this?


Thanks
Avatar of jcrumble
jcrumble

Running the same environment and the same code, I just copy over the top of my old files when I need to update my production app and run the piece of code to force the server to recognize the change.  Without knowing how integrated you have the code in your components, I would say that copying over the older piece of code should not present a problem.  If you have code that requires compiling you should simply have to recompile the one file and overlay it in production, not the whole app.  

In my case I setup an additional site between my development and production environment I use for testing.  Nothing elaborate, just a machine that can handle the app and allows me to test my code before moving it to production as well as allowing the users to test my changes before I make permanent changes to production.  It sounds to me like a similar environment might benefit you as well.

Good Luck,
Jeff
Something I would consider, is any code that might be changed from time to time, put it inline in the page, instead of in a code behind file.  This compiles when the page is loaded...
Avatar of muaddib2004

ASKER

" If you have code that requires compiling you should simply have to recompile the one file and overlay it in production, not the whole app."


But when you compile an ASP .NET project does it not compile all .cs code behind files into one .dll?

Are you suggesting there is a way of compiling one particular .cs file into is own dll?
How would that affect the functioning of the ASP .NET application as the .dll generated by compiling the entire project already takes into account the one particular .cs file I have made code changes to?

 
Well, that would depend on how you have your code and namespaces origanized.  If your code is contained in a single namespace then you might have problems. As Praesidium mentioned it would be better to put your code that might change from time to time inline so that it compiles when the page is loaded.  The further you go with your code in a state where it can't be changed, the more likely you are to find yourself in trouble when you have to change code.  Something else you might consider to driving as much of your changing code from a database.  I have tables that contain css classes, menu items, etc.  I don't know if this scenario fits into your site but it might be something to consider for your furture development where possible.  Also do you have to compile all your code behinds?  Granted it is faster on the webserver to compile them and call the DLL from your pages, but is it necessary everywhere in your site.  You might consider changing your code structure to allow for uncompiled code-behinds along with the compiled ones.  This would allow you to make changes to those pieces of code with just a drag and drop and run.

Good Luck,
Jeff
It's a bit of a hack, but you could always copy that one cs code-behind file out into another lib (another dll) change the namespace, and then change the @Page directive at the top of the page to point to your new namespace.class... I would keep the class as part of the main project though, so that the next app revision would have everything in a single lib again (make sure the changes go in both places).

/tim
So.. if wish to create a new spearate dll just for the .cs file I wish to update, what would be the easiest way to do this.. Would it merely involve changing the namespace name in the c# file and recompiling my development project (which will create a new dll for the .cs file in addition to re-creating the one for the entire project.)?
... and then copy the updated aspx with the newly created dll to the production server?
ASKER CERTIFIED SOLUTION
Avatar of taranki
taranki

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
"You might consider changing your code structure to allow for uncompiled code-behinds along with the compiled one"

Is it possible to include uncompiled .cs codebehind files..?  I thought IIS would not know what to do with a .cs source file