I have written a custom action in C# to check for the drive existence like below, I got stuck in between.
[CustomAction]
public static ActionResult MySimpleAction(Session session)
{
if (Directory.Exists("F:\\"))
{
return ActionResult.Success;
}
else
{
return ActionResult.Failure;
}
}
And in wxs file, I am running the custom action as like below.
<Binary Id="myAction" SourceFile="MyCustomAction.CA.dll" />
<CustomAction Id="myActionId"
BinaryKey="myAction"
DllEntry="MySimpleAction"
Execute="immediate"
Return="check" />
<InstallExecuteSequence>
<Custom Action="myActionId" After="InstallInitialize" > </Custom>
</InstallExecuteSequence>
If I run the msi in the target machine where I have F:\ drive then installation succeeds, if the target machine doesn’t have F:\ drive then Setup failed, I am getting error as “Setup wizard ended prematurely because of an error. Your system has not been modified.“
What I am trying to do here is, if F:\ drive is available in the target computer (My Custom action succeeds), I want to set my root drive as F:\, and I want to install the application in F:\MyApp\Bin
<Property Id="ROOTDRIVE"><![CDATA[F:\]]></Property>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="INSTALLFOLDERLOCATION" Name="MyApp">
<Directory Id="INSTALLLOCATION" Name="Bin">
if F:\ drive is not available in the target computer (My Custom action fails), I want to set my root drive as C:\, and I want to install in C:\MyApp\Bin
<Property Id="ROOTDRIVE"><![CDATA[C:\]]></Property>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="INSTALLFOLDERLOCATION" Name="MyApp">
<Directory Id="INSTALLLOCATION" Name="Bin">
How can I set the root drive property by using this custom action?
Thanks for the help!
I thank Christopher Painter and ChrisPatrick for helping me!!! the below code made the trick to work.
And in the .wxs file,