turn off assertions in VB 2005

  • Thread starter Thread starter douglass_davis
  • Start date Start date
D

douglass_davis

Say I would like to use assertions to make sure correct inputs are
given to a procedure. But, I want to do this in testing only, not in
production.

I saw Debug.Assert, which is nice, but does VB.NET have a feature where
you can turn off assertions on production code?
 
You can also use your own build types:

Goto the menu Build - Configuration Manager, and select <new> under
Active Configuration. Type you config name (ie MyTest), and copy the
settings from Release.

Now you can use the following in your code:

#IF CONFIG = "MyTest" THEN
your asserting code
#END IF

The above code is only compiled in your application when you are using
the MyTest configuration; as soon as you switch to Release, the code is
removed from your assembly.
 
As Kerry stated,
When you compile your app you can compile it for Debug or for Release.

The default is a Debug build, so Debug.Assert will be included.

You can use "Build - Configuration Manager - Active solution configuration"
to switch between Debug & Release builds of your application.

Alternatively there should be a "Solution configurations" combo box on the
standard toolbar.

NOTE: You may need to use "Tools - Options - Projects and Solutions - Show
advanced build configurations" to enable the solution configurations above.

As Theo suggests you can also use Build - Configuration Manager to define
new configurations, however for Debug.Assert this is not specifically
necessary.
 
Back
Top