Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » XML » Utilities » Downloads
 
Add your own
alternative version

XML Schema Reader Writer Plugin for VS 2005/2008

, 17 Apr 2009 CPOL
Schema based XML reader writer implemented as .NET COM generator
Plugin_setup.zip
setup.exe
xsdAddinSetup.msi
Test_project.zip
jjjjjjjjjjjjj
Properties
Resources
Test.csproj.user
Test.suo
XmlSchemaAddon_src.zip
CodeWrapperGenerator
ICSharpCode.NRefactory.dll
Properties
PostInstaller
Properties
Resources
XmlSchemaAddon.AddIn
PrintLIBID
PrintLIBID.suo
Properties
XmlSchemaAddon.suo
XmlSchemaAddon
ICSharpCode.NRefactory.dll
Properties
Resources
XmlSchemaAddon.AddIn
XmlSchemaAddon.csproj.user
xsdAddinSetup
Release
xsdAddinSetup.vdproj
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.IO;
using System.Xml;


namespace PostInstaller
{
    [RunInstaller(true)]
    public partial class PostInstaller : Installer
    {
        public PostInstaller()
        {
            InitializeComponent();
            this.BeforeUninstall += new InstallEventHandler(PostInstaller_BeforeUninstall);
        }

        void PostInstaller_BeforeUninstall(object sender, InstallEventArgs e)
        {
            string vsCfgInstallPath = GetVsAddInPath("8.0");
            if( vsCfgInstallPath != null )
            {
                if (File.Exists(vsCfgInstallPath))
                    File.Delete(vsCfgInstallPath);
            }

            vsCfgInstallPath = GetVsAddInPath("9.0");
            if (vsCfgInstallPath != null)
            {
                if (File.Exists(vsCfgInstallPath))
                    File.Delete(vsCfgInstallPath);
            }
        }

     
        public override void Install(IDictionary savedState)
        {
            System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName("devenv");
            if( null != process && process.Length > 0)
                throw new InstallException("Instance of visual studio was detected, all instances must be closed before installation");

            if (null == GetVsAddInPath("9.0") && null == GetVsAddInPath("8.0") )
                throw new InstallException("Visual studio 2005/ 2008 installation wasn't found");
                
            base.Install(savedState);

            // get the source directory of the installation from the default context parameters
            string TheAssemblyPath = this.Context.Parameters["assemblypath"];
            TheAssemblyPath = Path.GetDirectoryName(TheAssemblyPath) + Path.DirectorySeparatorChar;

            SavePluginCfgFile(TheAssemblyPath);
        }


        static string GetVsAddInPath(string vsVersion)
        {
            string regKey = string.Format(@"HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\{0}", vsVersion);
            string vsCfgPath = (string)Microsoft.Win32.Registry.GetValue(regKey, "VisualStudioLocation", null);

            if (vsCfgPath == null) return null;//VS not installed

            
            vsCfgPath = vsCfgPath + Path.DirectorySeparatorChar + "Addins";
            if (!Directory.Exists(vsCfgPath))
                Directory.CreateDirectory(vsCfgPath);
            
            vsCfgPath += Path.DirectorySeparatorChar + "XmlSchemaAddon.AddIn";
            return vsCfgPath;
        }

        static void SavePluginCfgFile(string installPath)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load( new MemoryStream(Properties.Resources.XmlSchemaAddon) );
            string strValue = xmlDoc.DocumentElement["Addin"]["Assembly"].InnerText;
            xmlDoc.DocumentElement["Addin"]["Assembly"].InnerText = installPath + strValue;

            //saving as VS 2008 plugin

            string cfgFilePath = GetVsAddInPath("9.0");
            if (null != cfgFilePath )
            {
                foreach (XmlElement child in xmlDoc.DocumentElement.ChildNodes)
                {
                    if (child == null || 0 != string.Compare(child.Name, "HostApplication", true))
                        continue;

                    child["Version"].InnerText = "9.0";
                }
                xmlDoc.Save(cfgFilePath);
            }                  

            //saving as VS 2005 plugin

            cfgFilePath = GetVsAddInPath("8.0");
            if( null != cfgFilePath )
            {
                foreach (XmlElement child in xmlDoc.DocumentElement.ChildNodes)
                {
                    if (child == null || 0 != string.Compare(child.Name, "HostApplication", true))
                        continue;

                    child["Version"].InnerText = "8.0";
                }
                xmlDoc.Save(cfgFilePath);
            }            
        }
    }


   
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

JadBenAutho
Software Developer Rontal Applications
Israel Israel
Born and raised in Israel, I've caught the programming virus at the age of 15.
Since than I can't stop coding.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150129.1 | Last Updated 17 Apr 2009
Article Copyright 2009 by JadBenAutho
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid