Conditional compilation in ASP. NET 2.0

Source: Internet
Author: User

In Web development, it is too troublesome to test the function of a single page. after entering the homepage username and password, you can go to the page you want to test after some operations. (In fact, no matter what development, testing a single function is very troublesome ). With a cautious attitude, I generally like to write a few tests once. It is obviously not economical to start the entire project to test each time.

I usually add a new configuration for testing in Solution, add a compilation command such as "Test" to it, and then put some Test conditions in the code, put the test method in this command. When the development team hasn't introduced the concept of unit testing, I don't want to use a new test project to do this. In addition, I don't know how to perform this process for pages like Web orders. Therefore, we are still familiar with this method by using our own compilation commands.

(I used to write some non-WEB content, but I also like to write the test method in a file with the class itself, and then use the compilation command to separate it. If you want to test it, select the configuration of "Test" directly in the development environment, and then start TestDriven to Test it. You don't need to start the entire project to save more effort on the machine. TestDriven is very useful.
If you use C # for development, in the development environment, if the current compilation condition is not met, the code will be grayed out and can be indented, not blind at all)

 

However, my tricks are a little useless in VS2005. Now WEB development is a little different from previous ones. No place can be found to add compilation commands. Non-WEB development can still find new ones. After a long time, I found that I have put some settings into Web. config, and Conditional compilation is no exception.

For example, you need to add a "Test" Conditional compilation command. In the Web. config file, add the following statement in the <compilation> section.

<Compilers>

<Compiler language = "vb"

Type = "Microsoft. VisualBasic. VBCodeProvider, System, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = B77A5C561934E089"

Extension = ". VB"

CompilerOptions = "/define: Debug = True/define: Trace = True/define: Test = True"/>

<Compiler language = "c #"

Type = "Microsoft. CSharp. CSharpCodeProvider, System, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = B77A5C561934E089"

Extension = ". cs"

CompilerOptions = "/d: DEBUG; TRACE; Test"/>

</Compilers>

 

Add a <compiler> to each language. If the corresponding language is not used in the project, ignore it and delete it. Generally, C # and VB are used a lot. I only use these two methods.

Web. after setting in config, you do not need to define the compilation command on every page to be tested. However, it is still not as good as before. You can simply select the configuration on the IDE toolbar, it is hard to write so many things now, and it is not easy to switch. For example, if I don't start it under "Test", I have to comment out the above section in Web. config.
According to MSDN, In. Net 2.0, the <compiler> element is deprecated. It seems that I am not doing this right.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.