asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Exploiting .NET's Advanced Deployment Features -- Cont'd
By Anthony Arslan


  • email this article to a colleague
  • suggest an article


    Custom Actions

    Custom Actions are installation components that will be invoked during the setup process. To view the Custom Actions editor, right-click on the setup project then click view --> Custom Actions as seen in Figure 12. By looking at figure 12, we can see that Custom Actions can be invoked at any four specific points: Install, Commit, Rollback and Uninstall. To satisfy our objectives I needed to set up some files and folders during the install step. If the specified folders are already in place I do not recreate them, but I do recreate files.

    Figure 12: The Custom Action Editor

    Creating a Custom Actions program is straightforward. We create a new Class Library project, SetupCustomActions that manipulates files/folders on the target machine during the installation. To do so, we created a project with the New Project Wizard, specifying Class Library as the template. By default, a class called Class1 is created in the project. Delete this class from the project and use the Add New Item wizard to add an Installer Class to the project, as shown in Figure 13.

    Figure 13: Adding an Installer Class to a custom action project

    Now, we are ready to write our code. As seen in the Figure 14.

    Figure 14: Setting up an installer class.

    It is important to notice that the SetupCustomAction class inherits the System.Configuration.Install.Installer and RunInstaller attribute is true [RunInstaller(true)]. Otherwise the SetupCustomAction will not be invoked by the setup program.

    To add code to the SetupCustomAction Class we first have to override the Install method.

    public override void Install(IDictionary stateSaver)
    {
    	base.Install (stateSaver);
    
    	string companyName = Context.Parameters["cName"];
    	CreateFilesFolders(companyName);
    }
    
    Then we create a configuration file. See the code for implementation.

    At this point, compile the SetupCustomAction using right-click on SetupCustomAction project then select Build. Now, we are ready to add our compiled class (specifically .dll) file to the setup project. To do so right-click the setup project Add --> File. Select the SetupCustomAction.dll from the Add Files dialog box (You may have to browse to the appropriate folder). The SetupCustomAction.dll will appear under the setup project.

    After adding the .dll to the Setup project, open the Custom Actions Editor by right-clicking on the Setup project in the Solution Explorer and choose View --> Custom Actions in the pop-up menu. In the Custom Actions Editor, right-click, on the Install folder and select the Add Custom Action... command from the pop-up menu then double-click on Applications folder on Select Item in Project dialog box and select SetupCustomAction.dll, then click OK, as seen in Figure 15.

    Figure 15: The SetupCustomAction.dll in the Select Item in Project dialog box

    Furthermore, we need to introduce the SetupCustomAction.dll to the setup project so that this component can be invoked during the installation process. We also have to link the user input to a variable that can be accessed from code. This is done by setting some properties of SetupCustomAction.dll, as shown in Figure 16.

    Figure 16: The properties of SetupCustomAction.dll under Custom Actions.

    The property CustomActionData associates a variable named cName with the COMPANYNAME_A1 input field. Once we have this association, we obtain the value entered using the following line of code.

    string companyName = Context.Parameters["cName"];
    
    Note: The CustomActionData takes a format of /name=value. Multiple values must be separated by a single space (i.e. /name1=value1 /name2=value2). Also, if the value has a space in it, it must be surrounded by quotes.

    Now, we're ready to write a method where we create an XML file. We record user's information in the XML file and read back from it at run time to provide a customized interface. At this point, recompile the setup program so it will be ready for distribution.

    Conclusion

    Writing custom applications has always been a hot topic among software developers. Customization has been attained using several different methods such as providing a separate set of license files for each end user. Visual Studio .NET now allows us to develop deployment projects where we can create custom actions through installer-derived classes. Using VS .NET's custom deployment feature, we are able to obtain input from the user and easily create configuration files during deployment. At run time, our application reads the data from the configuration file and customizes the application interface accordingly.

    References

    1. VS .NET Setup and Deployment Projects, asptoday.com.
    2. Deploy Apps With Ease
    3. Deploying Serviced Components
    4. MSDN

    About the Author

    Anthony Arslan is currently working as a developer for a large financial institution in Lincoln, Nebraska. He also teaches Microsoft Applications at a local college. Anthony holds a Master's degree in Computer Science. He can be reached at arslan@nefel.com.

    << Creating A Deployment Program

    Rate This Article

  • Other Articles
    Feb 23, 2005 - My Feature in Visual Basic 2005
    In this article, Thiru Thangarathinam demonstrates the different classes and features available through the My namespace. By providing a speed-dial that allows you to more quickly and effectively utilize .NET framework functionalities in your application, the My feature provides huge productivity improvements for .NET developers.
    [Read This Article]  [Top]
    Oct 6, 2004 - Creating Triggers Using Managed Code in SQL Server 2005
    Thiru Thangarathinam discusses taking advantage of the integation between the .NET CLR and SQL Server 2005 in order to do things like create triggers using managed code.
    [Read This Article]  [Top]
    Sep 8, 2004 - Custom Object Data Binding with .NET
    Developers often use brute force coding to marshal data between the GUI and application objects. In this article, Luther Stanton explains how to use .NET's out-of-the box data-binding functionality to make this job much easier.
    [Read This Article]  [Top]
    Aug 17, 2004 - The Perfect Service - Part 2
    Ambrose Little provides the complete source code for his 'Perfect Service' and explains how the .NET Service Manager enables features such as drag-n-drop deployment.
    [Read This Article]  [Top]
    Aug 12, 2004 - Middle-Tier Hosting: Enterprise Services, IIS, DCOM, Web Services, and Remoting
    There is broad-reaching debate about remoting, Web services, Enterprise Services, and DCOM. In short, it is a debate about the best technology to use when implementing client/server communication in .NET. Rocky Lhotka shares his thoughts on the issue while offering clear explanations of basic application architecture terminology.
    [Read This Article]  [Top]
    Jul 21, 2004 - COM Interop Exposed
    This article provides and excellent foundation for COM Interop. It reviews COM's background, explains how VB6 interacts with COM, and then shows how to design .NET components to smoothly interact with COM.
    [Read This Article]  [Top]
    Jun 24, 2004 - The Perfect Service - Part 1
    The first article in this two-part series shows how to get Ambrose Little's .NET Service Manager running and then how to add plug-n-play services to it using drag-n-drop or XCOPY.
    [Read This Article]  [Top]
    May 25, 2004 - Generics In-Depth
    Although generics are extremely useful, they also seem to have a certain mystique that cannot be readily explained. This article hopes to remove that aura of mystery by showing just how easy it is to use generics and how useful they can be in many common situations.
    [Read This Article]  [Top]
    May 11, 2004 - SharePoint Security and .NET Impersonation
    When implementing custom components that require access to restricted resources, implicit impersonation must be used. Jay Nathan shows how to create a class that makes using .NET Impersonation a snap.
    [Read This Article]  [Top]
    Mar 23, 2004 - Exploiting .NET's Advanced Deployment Features
    Tony Arslan shows how to use VS .NET's custom deployment feature to create configuration files on the target machine during installation.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info

    Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers