Showing posts with label Installer / Setup. Show all posts
Showing posts with label Installer / Setup. Show all posts

28 September 2014

Creating directory and copying files using Build Events

If we need to create any directory while we build the project or need to copy some files, in this case the build events comes really handy. 

To specify these events, navigate to the project properties >> Build Events and write these event for Pre or Post build event.


//Create a directory
md "$(SolutionDir)SomeDirectory\Rosources"

//Copying files
xcopy "$(SolutionDir)SourceFolder\Rosources" "$(SolutionDir)TargetFolder\Rosources" /r /y /f /d

20 November 2009

Installing AccessDatabaseEngine with Application Setup

If you are using Access2007 database in application then you need to have the accessdatabaseengine to make you application work, if MS Office is not installed on the client machine.

You need to perform the following steps to make accessdatabaseengine part of your application setup that installs it along with your application.

1. Download the AccessDatabaseEngine.exe from the following location-
http://www.microsoft.com/downloads/details.aspx?familyid=7554F536-8C28-4598-9B72-EF94E038C891&displaylang=en

2. Include AccessDatabaseEngine.exe in your setup:-
-Open the file system editor of your setup project.
-Add the AccessDatabaseEngine.exe in your application folder.

3. Include an Installer class to your main project if it is not there, and make sure that the RunInstaller attribute is set to true. [RunInstaller(true)]





4. Override the Install method in the Installer class.

public override void Install(IDictionary stateSaver)
{
    base.Install(stateSaver);
}

5. Generate event for the AfterInstall and write the following code in it to install the access database engine.
private void Installer1_AfterInstall(object sender, InstallEventArgs e)
{
    string str = System.Reflection.Assembly.GetExecutingAssembly().Location;
    string accessComponentFile = "AccessDatabaseEngine.exe";


    int indx = str.LastIndexOf('\\');
    str = str.Substring(0, indx);


    System.Diagnostics.Process prc = new System.Diagnostics.Process();
    try
    {
      prc.StartInfo.FileName = str + "\\" + accessComponentFile;;
      prc.StartInfo.Arguments = "/quiet";
      prc.Start();
      prc.EnableRaisingEvents = true;
      prc.Exited += new EventHandler(prc_Exited);
    }
    catch (Exception ex)
    {
      System.Windows.Forms.MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

The prc.StartInfo.Arguments = "/quiet"; installs the access database engine in silent mode.

6. Delete the AccessDatabaseEngine.exe from the client machine-

Write the following code in the process exited event of the process defined in the AfterInstall event.

void prc_Exited(object sender, EventArgs e)
{
    string str = System.Reflection.Assembly.GetExecutingAssembly().Location;
    string accessComponentFile = "AccessDatabaseEngine.exe";
    int indx = str.LastIndexOf('\\');
    str = str.Substring(0, indx);

    string FolderPath = str + "\\" + accessComponentFile;
    if (File.Exists(FolderPath))
    {
      try
      {
        File.Delete(FolderPath);
      }
      catch (Exception ex)
      {
      }
    }
}