Well, after much searching and trial and error I have solved this. I'm not sure if this is the best way, but it works.
Here's the scenario: I have an application I would like to deploy via a Visual Studio Setup project. In addition to my application files, I would like to create a subdirectory in the target directory that contains a batch (.bat) file. I would like this file to run at the end of the installation process.
Here's what you do:
- Create a setup project and configure as you normally would, including the subdirectory in which you'll place your batch file (you can just place it in the Application Folder directly if you don't want it in a subdirectory).
- In the "File System" view (right-click on the project in Solution Explorer->View->File System), add the batch file you want to execute and cmd.exe (C:WindowsSystem32cmd.exe)
- Open the "Custom Actions" view (right-click on the project in Solution Explorer->View->Custom Actions)
- Right-click on "Commit" and choose "Add Custom Action"
- Navigate to and select cmd.exe.
- Open the properties panel for the newly created custom action.
- Delete /Commit from the Arguments property.
- Enter:
/c "[TARGETDIR]subdirectorynameatchfile.bat"
in the Arguments property, where subdirectoryname should be replaced by the name of your subdirectory (if you put the batch file in a subdirectory like I did... if you didn't, the value should be /c "[TARGETDIR]batchfile.bat"
) and batchfile.bat should be the filename of your batch file.
That's it. The batch file will now be executed once the rest of the installation process is completed.
Here's an example for the sake of clarity:
My batch file: blah.bat
My subdirectory: mydir
The value of the Arguments for my custom action targeting cmd.exe would then be
/c "[TARGETDIR]mydirlah.bat"
Hope that helps someone!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…