In the blink of an eye, it has been 4 years since Microsoft launched the .net platform, and .net has also experienced upgrades from 1.0 to 1.1 to 2.0. Due to the attraction of various superior features of asp.net 2.0 and vs 2005 IDE, everyone is busy learning 2.0 and upgrading the project to vs 2005 for development. But in fact, many projects cannot be upgraded to new versions due to various reasons. As time goes by, the problem of project maintenance of old versions becomes more and more troublesome. Although .net was born not long ago, 4 years is enough time to accumulate a large number of projects.
I have a project developed with vs.net 2002, which has not been upgraded due to various reasons (mainly because the project has been running well for a while before vs.net 2003 came out, and other asp.net programs on the server Unable to adapt to the security requirements of .net 1.1).
When the company's development platform was upgraded, vs.net 2002 and vs.net 2003 were installed on the computer at the same time, which temporarily solved the maintenance of different versions of the project. Later, the project passed the maintenance period and had not been updated for a long time. My computer was also reinstalled, and vs.net 2002 was completely eliminated. But by 2005, customers were asking for modifications every one or two months, and they had to be fast. There was no other way. The customers were so awesome that they had to make changes even after the maintenance period. But here comes the problem. Without vs 2002, it cannot be compiled.
It is very troublesome to install .net framework 1.0 on the computer and manually call csc to compile the modified code. The project has a lot of references and writing the command line is very complicated. This is especially painful when the project has many folders. I also took the test and wrote a program to compile it, but I was lazy and never realized it.
Today I need to modify the program again, and suddenly I remembered that I used the Src attribute of the @Page directive once very early (in 2002). Using this attribute, asp.net will use its own compilation model instead of using the CodeBehind of the vs.net IDE. In this way, the code can be published without compiling it into a dll. When accessing the site, asp, net will automatically compile the aspx file and the .aspx.vb file together. There are two main disadvantages of this method: 1. The code file (.vb) must be published to the server, 2. vs.net IDE does not support it. Because of the second problem, I gave up using it and forgot about it. Now I am worried about not being able to compile the program. As long as the modified code can take effect, other shortcomings will not be considered. Anyway, all the source code is published to the server. I added a Src attribute to the @Page directive, using the same value as the CodeBehind attribute, pointing to the code file. Then modify the code in the .vb file. Refresh, the modifications take effect, and the maintenance is completed. So cool. That’s what I’ll do from now on. Since the vs.net IDE does not support it and it is mentioned on MSDN, not many people may know that .net has this compilation model. Share it now. If anyone is experiencing the same pain as me, you can also try to add Src to the page. Haha, it is simple and fast. Once the code is changed, it will take effect. No need to rack your brains to find tools to compile it.
Summary: Many people, including me, prefer to compile the program into a dll, which feels more like a released software. In fact, the method of "publishing all source code to the server and compiling the code completely during runtime" is very good and greatly simplifies future maintenance work. Many companies do projects for customers that do not actually need to hide the source code from customers. In this case, using this method will bring huge benefits to future maintenance work. No matter whether .net is upgraded n times or whether the corresponding version of development tools is installed on your computer, you don’t need to worry. Use Notepad Can handle everything.
Note: All versions of asp.net support this compilation mode, but the IDE of vs.net 2002 and 2003 does not support it and cannot open the design view. The newly released vs 2005 IDE supports this compilation mode. When using the Src attribute, the CodeBehind attribute is no longer required, but it is recommended that you still keep it. It can also help you if you suddenly need to return to the calculation view. The Inherits attribute is not required, but it is strongly recommended not to delete it, because if you directly bind the event in the control declaration of the aspx file (such as: OnClick="...."), there will be an error without the Inherits attribute.
Source: cwbboy BLOG