< .Net Framework Class Library 1 | Main | .Net Framework Class Library 3 >


 

 

The .NET Framework Class Library Review 2

 

 

 

 

 

The topic in this part is listed below. The code snippets if any are based on the new C++ .NET syntaxes.

  1. Metadata (continue)

 

AssemblyInfo.cpp contains definitions of the standard metadata items that you can modify as shown below.

#include "stdafx.h"

 

using namespace System;

using namespace System::Reflection;

using namespace System::Runtime::CompilerServices;

using namespace System::Runtime::InteropServices;

using namespace System::Security::Permissions;

 

//

// General Information about an assembly is controlled through the following

// set of attributes. Change these attribute values to modify the information

// associated with an assembly.

//

[assembly:AssemblyTitleAttribute("Meta1")];

[assembly:AssemblyDescriptionAttribute("")];

[assembly:AssemblyConfigurationAttribute("")];

[assembly:AssemblyCompanyAttribute("testing")];

[assembly:AssemblyProductAttribute("Meta1")];

[assembly:AssemblyCopyrightAttribute("Copyright (c) testing 2007")];

[assembly:AssemblyTrademarkAttribute("")];

[assembly:AssemblyCultureAttribute("")];

 

//

// Version information for an assembly consists of the following four values:

//

//      Major Version

//      Minor Version

//      Build Number

//      Revision

//

// You can specify all the value or you can default the Revision and Build Numbers

// by using the '*' as shown below:

 

[assembly:AssemblyVersionAttribute("1.0.*")];

[assembly:ComVisible(false)];

[assembly:CLSCompliantAttribute(true)];

[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];

And stdafx.cpp is shown below.

// stdafx.cpp : source file that includes just the standard includes

// Meta1.pch will be the pre-compiled header

// stdafx.obj will contain the pre-compiled type information

 

#include "stdafx.h"

2.        Open AssemblyInfo.cpp. Find the following part.

[assembly:AssemblyTitleAttribute("Meta1")];

[assembly:AssemblyDescriptionAttribute("")];

[assembly:AssemblyConfigurationAttribute("")];

[assembly:AssemblyCompanyAttribute("testing")];

[assembly:AssemblyProductAttribute("Meta1")];

[assembly:AssemblyCopyrightAttribute("Copyright (c) testing 2007")];

[assembly:AssemblyTrademarkAttribute("")];

[assembly:AssemblyCultureAttribute("")];

Metadata is added to C++ code by enclosing declarations in square brackets ([]). The assembly: part at the start means that this is an attribute that applies to an assembly, as opposed to a type within an assembly. There’s a set of standard attributes that you can use to change the metadata compiled into an assembly, and most of them are listed in AssemblyInfo.cpp.

 

3.        Edit the AssemblyCompanyAttribute line to contain some suitable name, like this:

[assembly:AssemblyCompanyAttribute("My Acme Company, Inc.")];

 

The assembly attributes - Visual C++ .NET

 

Figure 3

 

4.        Now build the project, which automatically creates the assembly for you.  If you run it, it is a classic “Hello World” example.

 

.NET console program sample output

 

Figure 4

 

5.   How can you be sure that the metadata in the assembly reflects your change? One way to find out is to use ILDASM. ILDASM is part of the .NET SDK. For Visual C++ .Net 2003, it is located in the \Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin directory. You can either start it from there or open a Microsoft Visual Studio .NET Command Prompt using the Programs Microsoft Visual Studio .NET 2003Visual Studio .NET Tools Visual Studio .NET 2003 Command Prompt entry on the Start menu.

 

Invoking the Visual Studio .NET 2003 command prompt

 

Figure 5

 

The following image is for Visual C++ Express Edition 2005.

 

Invoking the Visual Studio .NET 2005 command prompt

 

Figure 6

 

6.   A console window will open that has the path set to include all the Visual Studio .NET and .NET SDK directories, so you can simply type ildasm to start the program. Type the executable, ildasm.

 

Invoking the ILDASM at command prompt - Visual Studio .NET 2003

 

Figure 7

 

Invoking the ILDASM at command prompt - Visual Studio .NET 2005

 

Figure 8

 

ILDASM page  

 

Figure 9

 

7.        When the ILDASM window opens, use the File menu to browse for the Meta1.exe executable and open it. You should see something like the following figure.

 

Using ILDASM - opening the assemblies of the exe file

 

Figure 10

 

Metadat information in the assembly seen through ILDASM

 

Figure 11

 

8.        Double-click MANIFEST, which will open a separate window displaying the assembly metadata.

 

The manifest of the changed metadata

 

Figure 12

 

Scroll down until you find the AssemblyCompanyAttribute line, which should read something like this:

.assembly Meta1

{

  .custom instance void [mscorlib]System.Reflection.AssemblyDelaySignAttribute::.ctor(bool) = ( 01 00 00 00 00 )

  .custom instance void [mscorlib]System.Reflection.AssemblyTitleAttribute::.ctor(string) = ( 01 00 00 00 00 )

  .custom instance void [mscorlib]System.Reflection.AssemblyCompanyAttribute::.ctor(string) = ( 01 00 15 4D 79 20 41 63 6D 65 20 43 6F 6D 70 61   // ...My Acme Compa

                                                                                                6E 79 2C 20 49 6E 63 2E 00 00 )                   // ny, Inc...

  .custom instance void [mscorlib]System.Reflection.AssemblyDescriptionAttribute::.ctor(string) = ( 01 00 00 00 00 )

Although the contents are given in hex, you can see that the metadata does reflect the change you made to the project.

 

 

Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7 | Part 8

 


 

< .Net Framework Class Library 1 | Main | .Net Framework Class Library 3 >