Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1236
  • Last Modified:

Visual Studio Installer Custom Action VBS File copy config from installer dir to target dir

Hi guys,
I'm creating a MSI setup with the Visual Studio Installer.

Its supposed to copy a config file that resides in the installer directory to the target directory.

I therefore created this VBS:
' Config file verschieben
dim fso, file
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile WScript.Arguments(0), WScript.Arguments(1), true ' Installerdir\config, Targetdir, überschreiben
set fso = nothing

Open in new window



which works when run from CommandLine.

However, when I add a customaction and set its CustomActionData to
"[INSTALLDIR]\config" "[TARGETDIR]\"

I get an error message when running the setup.


What am I doing wrong? Is there an easier way to accomplish this?

I cannot add the config file to the setup project, since it's generated by a separate tool and added to the already compiled setup.
0
Scoox
Asked:
Scoox
  • 2
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
in CustomActionData add:

/TARGETDIR="[TARGETDIR]\" /SOURCEDIR="[SOURCEDIR]\"

SOURCEDIR -> is where the .Msi installer located
TARGETDIR-> is the target installation directory of the .Msi installer

so basically, in your custom action dll, you run the script like this:

Process proc = Process.Start("cscript", string.Format("\"{0}\" \"{1}\"",
Path.Combine(Context.Parameters["SOURCEDIR"], "<ScriptName>.vbs"),  
Path.Combine(Context.Parameters["TARGETDIR"], "<ScriptName>.vbs")));
proc.WaitForExit();
0
 
funazonkiCommented:
If you have an installer project, you can just add the config file to the installer project's list of files and it will get delivered to the target directory at install time.
0
 
Meir RivkinFull stack Software EngineerCommented:
@funazonki -
i think Scoox said that he cannot add the config file to the setup project cause it is generated by separated tool.


@Scoox -
why not copy the config file via code from the custom action dll?
when you override OnInstall(), you can call:
File.Copy(
Path.Combine(Context.Parameters["SOURCEDIR"], "app.config"),
Path.Combine(Context.Parameters["TARGETDIR"], "app.config"), true);

which is simpler than doing it via script.

0
 
ScooxAuthor Commented:
Thank you. I thought it would be hard to do it with custom dll. Can I write that in C#? Do you have a link for a tutorial?
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now