Getting rid of the `My` namespace

Recently, I have been developing a Vb.Net application, and I try to make it as easy as possible (i.e. make binary files as small as possible).

I did all the trivial things, but while looking at the binary using ILDasm , I noticed that it has My namespace , with many methods, although I do not use any of them in my program, It seems that there are default methods for each form Get/Set and other methods.

Is there any way to get rid of them?
Or can you show me an example of using default binary related methods?

PS : I think it will not matter much in binary size: I just ask about it out of curiosity; why does the compiler bind useless methods in each binary? Perhaps I will find out that these methods are actually used somewhere under the hood.

PPS : here is a minimal example:

 Module Test Sub Main() End Sub End Module 

Output: ILDasm output

+4
source share
3 answers

After violently scratching the head ...:

How much is included depends on the value of _MYTYPE define. All this is documented in MSDN , I could not find it at first.

+3
source

Follow these steps:

  • Click Show All Files in Solution Explorer
  • Open the My Project branch
  • Open the Settings.settings branch
  • Open Settings.designer.vb
  • Edit the My namespace as you like

image

There is an additional subspace My called My.Resources , which hides under the Resources.resx branch.

+3
source

To remove most of the generated types in the My namespace, you need to set _MYTYPE define to Empty . To do this, you will need to open the .vbproj file in a text editor (using Visual Studio, you can do this by first unloading the project, and open it).

Look for the <MyType> element in the first <PropertyGroup> and change its value to Empty :

 <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProjectGuid>{C6DC5A64-1E50-48B0-97A5-649D2D323E5E}</ProjectGuid> <OutputType>Library</OutputType> <RootNamespace>Some.Component</RootNamespace> <AssemblyName>Some.Component</AssemblyName> <FileAlignment>512</FileAlignment> <MyType>Empty</MyType> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> <SccProjectName>SAK</SccProjectName> <SccLocalPath>SAK</SccLocalPath> <SccAuxPath>SAK</SccAuxPath> <SccProvider>SAK</SccProvider> </PropertyGroup> 

I did not find a way to remove the InternalXmlHelper that Visual Studio creates.

As ClΓ©ment pointed out, configure the My namespace using the other _MYTYPE values _MYTYPE defined.

This procedure will work for Visual Studio 2012.

+1
source

All Articles