I've been digging around Google trying to find the appropriate way to determine the installation path selected by a user from the install wizard.
Basically I'm running into an issue where my service can't create files in it's own directory because it lacks the proper permissions. I'm assuming the correct way to resolve this is to make sure that whatever account the service is using is given appropriate file permissions on it's folder.
But before I can even tackle how to set permissions through .Net I need to know the installation folder. I'm using an install project which has an Installer class which contains a ServiceInstaller
control as well. Both have the Context
property so I've been checking that for the parameters that are available when the AfterInstall event fires for each of the respective installers. I thought at first I'd be seeing the TargetDir
property set but that hasn't been the case. I am however seeing AssemblyPath
set and pointing to the executable of the appropriate folder.
Essentially I just want to make sure that this is the appropriate method I should be using:
private void ProjectInstaller_AfterInstall(object sender, InstallEventArgs e)
{
string InstallPath = System.IO.Path.GetDirectoryName(serviceInstaller1.Context.Parameters["AssemblyPath"]);;
}
If you've already installed it and want to change the location, you must uninstall Visual Studio and then reinstall it. In the Shared components, tools, and SDKs section, select the folder where you want to store the files that are shared by side-by-side Visual Studio installations.
The \Microsoft\VisualStudio\Shared directory is where Visual Studio stores the files that are shared by side-by-side Visual Studio installations. SDKs and tools are also stored in this directory.
In Visual Studio, click Tools > Options. Expand Projects and Solutions and click Locations. The Projects location field defines the default location for storing new projects. You can change this path if you are using a different working folder.
By default, Visual Studio builds each project in a solution in its own folder inside the solution. You can change the build output paths of your projects to force all outputs to be placed in the same folder.
I found that the solution that Berg gave works for me except using this value for the CustomActionData property:
/TargetDir="[TARGETDIR]\"
Note the addition of the backslash. See this article on MSDN.
Your custom action is a deferred custom action and only certain properties are available to it, see the following page for more details, http://msdn.microsoft.com/en-us/library/aa370543(VS.85).aspx. You may be able to add the TARGETDIR property to the CustomActionData in Visual Studio 2008; however, I have not worked with Visual Studio 2008 as an authoring tool.
Doing complicated installs in Visual Studio 2008 is very difficult because it abstracts away a number of key features of MSI. I would strongly suggest taking a look at WiX.
Even if you don't use WiX, you will want to download Orca, http://msdn.microsoft.com/en-us/library/aa370557(VS.85).aspx and use it to validate your install. This will save you countless hours later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With