3

I would like to know the path where the msi is located whithin the InstallerClass that I use as a custom action in the setup.

I tried using properties like path, SrcDir etc. in Context.Parameters, but those values do not exsist (Throws NullReferenceException). Is there any other way way of getting that path or any reason why those values are null???

Thanks

awe
  • 21,938
  • 6
  • 78
  • 91
Dulini Atapattu
  • 2,735
  • 8
  • 33
  • 47

2 Answers2

6

You will need to pass the relevant property in action data via the Property window in VS:

/sourceDir="[SourceDir]\"

Then, use the context to retrieve it:

string path = Context.Parameters["SourceDir"];
awe
  • 21,938
  • 6
  • 78
  • 91
Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
  • it works, but for a vs2010 you'll get and extra '\' that you have to remove in the installer class code. – dmihailescu Sep 25 '13 at 16:19
  • could any one please tell me where I can set "/sourceDir="[SourceDir]\" ? – Roshil K Mar 28 '15 at 14:56
  • @Roshil, it's probbaly 4 years too late but here's the answer to your question: You have to create a class library and add an Installer Class to it. In that you override Install to do what you want. Then in your setup and deployment project you right click and go to View -> Custom Actions. Under Install you add "Primary output from MyInstallerClassLibrary (Active)". When you click on that, you can set the CustomActionData parameter to /SrcDir="[SourceDir]\". Then in your class library you can access that dir with this.Context.Parameters["SrcDir"]. – zappa Feb 21 '19 at 09:47
0

Installer Class have many limitations and behave very poorly when they fail ( fragile ). I suggest you look at C# managed custom actions using Deployment Tools Foundation (DTF) in Windows Installer XML ( WiX ). The output of this project type is C++ equiv and can be consumed by a Visual Studio Setup and Deployment Project ( which I also wouldn't reccomend using. )

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100