Blue Theme Orange Theme Green Theme Red Theme
 
Mindcracker MVP Summit 2012
Home | Forums | Videos | Photos | Blogs | Beginners | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Mindcracker MVP Summit 2012
Search :       Advanced Search »
Home » Assemblies » Enhancements in Assemblies and Versioning in Visual Studio 2005

Enhancements in Assemblies and Versioning in Visual Studio 2005

The article discusses a couple of features introduced for assembly and versioning in Visual Studio 2005 such as referencing assemblies, registering assemblies to GAC, digital signing and friend assemblies.

Page Views : 7884
Downloads : 0
Rating :
 Rate it
Level : Intermediate
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Discover the top 5 tips for understanding .NET Interop
Become a Sponsor
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

The article discusses a couple of new features introduced for assemblies and versioning in Visual Studio 2005.

1. Referencing an Executable

This feature helps the developer to reference an .EXE file from the code. Visual Studio 2005 allows developers to add a reference to both library and EXEs. This is used to access the class files which are inside an .EXE file. 

In the below example, the client in the assembly named EXE 1 can consume Class D, which resides in the application assembly named EXE 2 

2. Installing Executables to to Global Assembly Cache

In Visual Studio 2003 you could not able to install application assemblies in GAC.In Visual Studio 2005 you can even add application assemblies to the GAC .You can install Exe to GAC.  

3. Friend Assemblies

An interesting assembly-level attribute introduced by .NET 2.0 is the InternalsVisibleTo attribute, defined in the System.Runtime.CompilerServices namespace. The InternalsVisibleTo attribute allows you to expose internal types and methods to clients from another specified assembly. This is also known as declaring a friend assembly.

[Assembly: InternalsVisibleTo ("MyClient")]
   
4. Supplying Assembly Version Number

In Visual Studio 2003, you had to manually write the various assembly-level attributes, including the version number. Visual Studio 2005 provides visual editing of all the attributes commonly found in the Assembly Info file. Visual Studio 2005 will even auto-populate certain values such as company name and copyright statements based on the information found in the Registry as part of Windows activation process.

To specify the version number using Visual Studio 2005, bring up the assembly properties and open the application tab. Next click the "Assembly Information" button to display the Assembly Information dialog.

5. Signing Assemblies

In old versions of .net you had to create strong name manually and you have to mention the file name in Assembly info.vb  file . In visual studio 2005, it provides to sign the assembly and we can even protect with encryption keys in visual studio environment.

In the project properties, select the "Signing" pane By checking the "Sign the assembly" checkbox, you instruct the compiler to sign the assembly with the key file specified.

 

The Choose a strong name key file combo box will allow you to either create a new key or to browse to an existing file. If you choose to create a new key, Visual Studio 2005 will launch the Create Strong Name Key dialog box shown in Figure.

We can generate strong name in plain and password-protected. If you uncheck the Protect my key file with a password checkbox, Visual Studio 2005 will generate a file with the name specified and with the snk (Strong Name Key) extension. Visual Studio 2005 will generate a file with the name specified and with the pfx (Personal Information Exchange) extension. The pfx file is more secure because whenever another user tries to use the file, that user will be prompted for the password. The other advantage of a pfx file is that you can add it to a certificate container (see the sidebar Protecting Your Keys).If instead of creating a new key file you would like to browse for an existing key, Visual Studio 2005 will bring up a dialog letting you browse for either .snk or .pfx files. Once you have selected a file, Visual Studio 2005 will copy that file to the project folder. In addition, unlike Visual studio 2003, Visual studio 2005 does not use attributes for storing the key file name. Instead, it persists that in the project settings. Whenever create if we sign the assembly for strong name, Visual Studio 2005 creates and .pfx file adds to solution as shown in Figure.

6. Extern alias Keyword

In .NET 2.0, by default, all types are rooted in a namespace called global. You don't need to explicitly use the global namespace since it is always implied by default. The global namespace is instrumental in resolving type name conflicts, especially when multiple assemblies are involved.

When you add an assembly reference, it is possible to create a conflict with another type already defined by your application in another assembly it references. For example, consider the MyApplication.exe and MyLibrary.dll assemblies, which both define the class My Class in the namespace, My Namespace.

'In MyApplication.exe

Namespace MyNamespace

    Public Class [MyClass]

    End Class '[MyClass]

End Namespace 'MyNamespace

 

'In MyLibrary.dll

Namespace MyNamespace

    Public Class [MyClass]

    End Class '[MyClass]

End Namespace 'MyNamespace

 

Each definition of MyClass is completely distinct, providing different methods and behaviors. If you add a reference to MyLibrary.dll from within MyApplication.exe, when you try to use the type MyClass like so

 

Dim MyNamespace As Using

 

Dim obj As New [MyClass]()

 

The compiler will issue an error because it does not know how to resolve it that is; it doesn't know which definition of MyClass to reference.

VB.Net 2.0 allows you to resolve type name conflicts by aliasing the assembly reference. To alias an assembly, first add a reference to it in Visual Studio 2005. Next, expand the Reference folder in the Solution Explorer, and display the properties of the referenced assembly .

 

If you added the reference by browsing to the assembly, the Aliases property will be set explicitly to global.

Next, add as the first line of the file the extern alias directive, instructing the compiler to include the types from the alias in the search path.

MyLibraryAlias As [alias]

You can now refer to the class MyClass from MyLibrary.dll.

MyLibraryAlias::MyNamespace.MyClass obj
obj = new MyLibraryAlias::MyNamespace.MyClass()

Note that the extern alias directive must appear before any using directives, and that all types in the MyLibrary.dll can only be referred to via the alias, because these types are not imported to the global scope.

Using aliases and fully qualified namespaces may result in exceedingly long lines. As shorthand, you can also alias the fully qualified name.

Imports MyLibrary = MyLibraryAlias::MyNamespace

 

Dim obj As MyLibrary.MyClass

obj = New MyLibrary.MyClass()

Summary

In this article, I discussed some new features introduced for assemblies and versioning in .NET 2.0 and Visual Studio 2005.

NOTE: THIS ARTICLE IS CONVERTED FROM C# TO VB.NET USING A CONVERSION TOOL. ORIGINAL ARTICLE CAN BE FOUND ON C# CORNER (http://www.c-sharpcorner.com/).

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Sairam
Rambabu is software developer. He is interested in Microsoft Technologies.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Mindcracker MVP Summit 2012
Become a Sponsor
 Comments
Team Foundation Server Hosting
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.