Customizing Which Objects are Available in My (Visual Basic)
This topic describes how you can control which My
objects are enabled by setting your project's _MYTYPE
conditional-compilation constant. The Visual Studio Integrated Development Environment (IDE) keeps the _MYTYPE
conditional-compilation constant for a project in sync with the project's type.
Predefined _MYTYPE Values
You must use the /define
compiler option to set the _MYTYPE
conditional-compilation constant. When specifying your own value for the _MYTYPE
constant, you must enclose the string value in backslash/quotation mark (\") sequences. For example, you could use:
/define:_MYTYPE=\"WindowsForms\"
This table shows what the _MYTYPE
conditional-compilation constant is set to for several project types.
Project type | _MYTYPE value |
---|---|
Class Library | "Windows" |
Console Application | "Console" |
Web | "Web" |
Web Control Library | "WebControl" |
Windows Application | "WindowsForms" |
Windows Application, when starting with custom Sub Main |
"WindowsFormsWithCustomSubMain" |
Windows Control Library | "Windows" |
Windows Service | "Console" |
Empty | "Empty" |
Note
All conditional-compilation string comparisons are case-sensitive, regardless of how the Option Compare
statement is set.
Dependent _MY Compilation Constants
The _MYTYPE
conditional-compilation constant, in turn, controls the values of several other _MY
compilation constants:
_MYTYPE | _MYAPPLICATIONTYPE | _MYCOMPUTERTYPE | _MYFORMS | _MYUSERTYPE | _MYWEBSERVICES |
---|---|---|---|---|---|
"Console" | "Console" | "Windows" | Undefined | "Windows" | TRUE |
"Custom" | Undefined | Undefined | Undefined | Undefined | Undefined |
"Empty" | Undefined | Undefined | Undefined | Undefined | Undefined |
"Web" | Undefined | "Web" | FALSE | "Web" | FALSE |
"WebControl" | Undefined | "Web" | FALSE | "Web" | TRUE |
"Windows" or "" | "Windows" | "Windows" | Undefined | "Windows" | TRUE |
"WindowsForms" | "WindowsForms" | "Windows" | TRUE | "Windows" | TRUE |
"WindowsFormsWithCustomSubMain" | "Console" | "Windows" | TRUE | "Windows" | TRUE |
By default, undefined conditional-compilation constants resolve to FALSE
. You can specify values for the undefined constants when compiling your project to override the default behavior.
Note
When _MYTYPE
is set to "Custom", the project contains the My
namespace, but it contains no objects. However, setting _MYTYPE
to "Empty" prevents the compiler from adding the My
namespace and its objects.
This table describes the effects of the predefined values of the _MY
compilation constants.
Constant | Meaning |
---|---|
_MYAPPLICATIONTYPE |
Enables My.Application , if the constant is "Console," Windows," or "WindowsForms":- The "Console" version derives from ConsoleApplicationBase. and has fewer members than the "Windows" version. - The "Windows" version derives from ApplicationBase.and has fewer members than the "WindowsForms" version. - The "WindowsForms" version of My.Application derives from WindowsFormsApplicationBase. If the TARGET constant is defined to be "winexe", then the class includes a Sub Main method. |
_MYCOMPUTERTYPE |
Enables My.Computer , if the constant is "Web" or "Windows":- The "Web" version derives from ServerComputer, and has fewer members than the "Windows" version. - The "Windows" version of My.Computer derives from Computer. |
_MYFORMS |
Enables My.Forms , if the constant is TRUE . |
_MYUSERTYPE |
Enables My.User , if the constant is "Web" or "Windows":- The "Web" version of My.User is associated with the user identity of the current HTTP request.- The "Windows" version of My.User is associated with the thread's current principal. |
_MYWEBSERVICES |
Enables My.WebServices , if the constant is TRUE . |
_MYTYPE |
Enables My.Log , My.Request , and My.Response , if the constant is "Web". |