Solved

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

Posted on 2004-10-06
9
965 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:muaddib2004
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 4

Expert Comment

by:jcrumble
ID: 12239693
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
0
 
LVL 6

Expert Comment

by:Praesidium
ID: 12242718
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...
0
 

Author Comment

by:muaddib2004
ID: 12244265
" 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?

 
0
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 
LVL 4

Expert Comment

by:jcrumble
ID: 12244899
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
0
 

Expert Comment

by:taranki
ID: 12245345
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
0
 

Author Comment

by:muaddib2004
ID: 12245439
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.)?
0
 

Author Comment

by:muaddib2004
ID: 12245454
... and then copy the updated aspx with the newly created dll to the production server?
0
 

Accepted Solution

by:
taranki earned 125 total points
ID: 12245604
you will have to add a new project (or create a new solution and add a project).  I would add a class library project, make sure that the System.Web was in my references, add my class with a new namespace, and compile that project.  Note, this project can still be part of your total solution if you wish, but I expect this is sort of a one-off type of thing, so a new solution may be in order.

Once you compile your new project into its dll, copy it to the server, and update the @Page directive in the aspx that should use it.  Note, if you have several pages that need updating this way, you could put multiple classes in this new project, just make sure to update each aspx file accordingly.

If you have updated aspx files, then just make sure that their @Page points to your new namespace and classes, and copy them up to your server with the new dll.  The dll goes side-by-side with your existing project in the /bin directory, and your aspx's go wherever, to replace your existing ones.

I hope that clarifies a bit...
/tim
0
 

Author Comment

by:muaddib2004
ID: 12245757
"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
0

Featured Post

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will learn how to dynamically set the form action using jQuery.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question