Customizing Which Objects are Available in My
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":
|
_MYCOMPUTERTYPE |
Enables My.Computer, if the constant is "Web" or "Windows":
|
_MYFORMS |
Enables My.Forms, if the constant is TRUE. |
_MYUSERTYPE |
Enables My.User, if the constant is "Web" or "Windows":
|
_MYWEBSERVICES |
Enables My.WebServices, if the constant is TRUE. |
_MYTYPE |
Enables My.Log, My.Request, and My.Response, if the constant is "Web". |
See Also
Concepts
How My Depends on Project Type
Conditional Compilation Overview