Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Install Project: Get Target Directory

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"]);;
}
like image 845
Spencer Ruport Avatar asked Feb 18 '10 23:02

Spencer Ruport


People also ask

How do I change the install path in Visual Studio?

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.

Where is Visual Studio installation path?

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.

How do I change the target path in Visual Studio?

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.

Where do my Visual Studio builds go?

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.


2 Answers

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.

like image 68
YWE Avatar answered Sep 20 '22 17:09

YWE


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.

like image 45
LanceSc Avatar answered Sep 21 '22 17:09

LanceSc