|
-
Apr 4th, 2011, 11:11 AM
#1
Thread Starter
Hyperactive Member
Setup Project Change SourcePath of Content Files
Hi all,
Is it possible to change source path of content files in setup project? I need to copy some of files located in source directory to installation directory while installation.
Thanks in advance
I am using .NET 2010 with Windows 7
-
Apr 4th, 2011, 11:19 AM
#2
Addicted Member
Re: Setup Project Change SourcePath of Content Files
I am not sure I follow you... What do you mean located in the source directory? (I imagine installation directory is your "Application Folder" in the "File System on Target Machine")
I might be completely wrong here but:
Have you tried creating a custom action? This can be in the form of a dll that can have an installer class that can copy files from one folder to another?
-
Apr 4th, 2011, 11:41 AM
#3
Thread Starter
Hyperactive Member
Re: Setup Project Change SourcePath of Content Files
I have already created custom action project to copy files from source directory to installation directory. but it's causing problem when I repair application. I am not getting [SOURCEDIR] variable that I have set from CustomActionData.
/TARGETDIR="[TARGETDIR]\" /SOURCEDIR="[SOURCEDIR]\ "
Here is the code.
Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.Windows.Forms;
namespace CustomInstallerProject
{
[RunInstaller(true)]
public partial class CopyFileInstaller : Installer
{
public CopyFileInstaller()
{
InitializeComponent();
}
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
string targetDir = this.Context.Parameters["TARGETDIR"].Trim();
string sourceDir =this.Context.Parameters["SOURCEDIR"].Trim();
string dbFile = "xyz.mdf";
string dbFileLog = "xyz_log.ldf";
string addressFile = "add.dll";
bool succeeded = true;
if (succeeded) CopyFile(sourceDir, targetDir + @"Data\", dbFile, false, "[ErrorCode: 11] Database file is missing. Please contact your vender.", "[ErrorCode: 12] Unexpected error occured while creating database. Please contact your vender.");
if (succeeded) CopyFile(sourceDir, targetDir + @"Data\", dbFileLog, false, "[ErrorCode: 21] Database file is missing. Please contact your vender.", "[ErrorCode: 22] Unexpected error occured while creating database. Please contact your vender.");
if (succeeded) CopyFile(sourceDir, targetDir, addressFile, true, "[ErrorCode: 31] Address file is missing. Please contact your vender.", "[ErrorCode: 32] Unexpected error occured while copying address file. Please contact your vender.");
}
private bool CopyFile(string sourceDir, string targetDir, string fileName, bool overwrite, string fileMissingMessage, string unexpectedErrorMessage)
{
bool result = true;
try
{
if (!System.IO.File.Exists(sourceDir + fileName))
{
result = false;
throw new InstallException(fileMissingMessage);
}
else
{
bool copyFile = true;
if (System.IO.File.Exists(targetDir + fileName) && !overwrite)
{
copyFile = false;
}
if (copyFile)
{
System.IO.File.Copy(sourceDir + fileName, targetDir + fileName, overwrite);
}
}
}
catch (Exception ex)
{
result = false;
MessageBox.Show(sourceDir);
throw new InstallException(unexpectedErrorMessage);
}
return result;
}
}
}
I am using .NET 2010 with Windows 7
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|