ASP.NET WebSite Publishing vs. Copy?

I ran into many publishing problems, for example, when you need to make small changes to the code, sometimes the generated DLL file (dll file, for example, default.aspx.CS when publishing) cannot be recognized by IIS saying that the codebehind is incorrect or that something like that. Sorry I don’t remember the exact error message. I hope you know what I mean at the moment.

Therefore, I usually do a simple Copy Paste operation instead of publishing.

Could you tell me what I am missing by NOT using the Publish method? Which is better published? Or which one do you prefer, why?

In essence, these are the pros and cons.

Thankyou

+6
source share
2 answers

Well, it depends on what you mean by "copy":

With Publishing , you have options to pre-compile all or part of your application. You can publish to a local folder in your file system (instead of the target / host), and then copy the updated file (only). If you do the “code behind” (C # / vb code), it means that you most likely will need to “copy” / overwrite the dlls . It is clear that if you make changes to the content (html / razor / script / etc changes), you will also need to copy and overwrite them.

If you are new to deployment, you can simply copy / overwrite "everything", which is the safest way. Once you get more experience, you will “know” what assets you need to update (one or more dlls and / or content code, not “all”). There is no magic in this, usually just a question about the timestamp of the dll / file after you use published (locally) or rebuild your web application.

I would recommend doing local publish so that you can see what is really needed on your server. Files published to your local file system / folder must be on your host / server. This will allow you to visualize and remove any "secret" for Publishing :

  • you will see what is actually needed (on your server) and what is not
  • You will see a timesstamps file that helps you find out which files were actually modified, and those that were not (and therefore do not need to be updated).
  • After you receive it, you do not need to “copy” / ftp “everything” and just update files that have actually been changed (only).

So, “copy” may mean higher, or if you say that you just copy all of your development code (raw (vb/cs)html/cs/vb ) to your host, it means that your site will be dynamically compiled , as each resource is needed / requested (nothing is pre-compiled ). It's also “easy”, but you lose pre-compilation , which means there is a delay when each of your web pages is requested / needed (ASP.net needs to be dynamically compiled). In addition, you also host the source code on the server. This may not mean much depending on your situation, but this is another thing to consider.

Here is more information about precompilation and options .

+13
source

Assuming we look at the aspx page and its aspx.cs code behind the file, there are three alternative ways to deploy your site:

  • You can copy both in iis. Aspx will compile to .cs on first request, and then both .cses will compile to temp.dll
  • You can “publish” iis, this will compile the code behind the class in .dll, but copy aspx intact. Aspx will be translated to .cs and then to .dll on first request
  • You can “publish” the site and then manually recompile it with aspnet_compiler. The publication will compile the code behind the .dll, as before, but then pre-compiling will clean your .aspx files, deleting their contents and moving the compiled code to another .dll.

All three models have their pros and cons.

The first of them is easiest to update gradually, but at the same time it is the most open for unwanted changes.

The second is also easy, can be called from vs, it closes the possibility of some unwanted changes on the server, but .aspxses still needs time to compile on first request

The third one takes time and some manual actions, but prevents any changes, and also speeds up the site warm-up, since data collection is not required. This is great for general environments.

+6
source

All Articles