Reputation: 149
I am trying to make an application using windows installer as it's install method. When the installation succeeds I want to get the path where the primary output is located that I configured in the installer. In my case the primary output is in the folder [ApplicationData(Installroot)]\Bin\
.
I also have a custom settings file called App.Settings in 1 my Class Library which controls several settings like file locations who are relative to the install location.
So the idea is that when the installation succeeds it should call the App.Settings and save the install folder to the settings file.
I already made an Install class and put it inside the Class Library. I am not sure if it is supposed to be in that project though. This is the code of the Install Class:
using System.Collections;
using System.ComponentModel;
namespace WaspbaneModels
{
[RunInstaller(true)]
public partial class Installer : System.Configuration.Install.Installer
{
public Installer()
{
InitializeComponent();
}
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
}
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
SettingsControl.BaseURL = Context.Parameters["assemblypath"];
SettingsControl.Save();
}
public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);
}
public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);
}
}
}
In this code SettingsControl is the class that takes care of the Settings simply with some properties. I used this class so that my Windows Forms project also can access these settings.
In the Custom Actions tab I also added the Primary Output to everything. I am also not sure if this is correct because I think the Primary Output contains all .dll files including the Class Libraries.
I am not really sure where to continue from this point however because the Settings are not saved. I simply check this by putting up a messagebox at the startup of the application giving me the value of the setting.
Anyone interested in more data of the project just ask. I just won't post everything at once yet.
EDIT:
After some more testing I managed to find out that the Installer class isn't being called upon. I added something that would write out to a file when the method would've been called but nothing happened.
Therefore my question now is: How do I add the Custom Action to the Setup project properly?
Upvotes: 2
Views: 18282
Reputation: 129
I had the same problem today.
My issue had to do with the project type I was using as Class Library.
I was selecting a new project of type Class Library.
I changed it to Class Library (.NET Framework).
Upvotes: 0
Reputation: 151
I had this same problem. After much frustration, I discovered that the msi installer only uses the app's installer class from the first install during an update when RemovePreviousVersions = true
. Thus, if you uninstall the app and reinstall, it works.
As a workaround, I found that uninstalling the previous version earlier in the install process fixes the issue. The sequence number of RemoveExistingProducts
must be moved to a lower value in the msi installer documented in SO here. This can be done manually using orca or automatically by running a vbs script found here as a VS PostBuildEvent:
cscript.exe ..\Msi_Fix_RemoveExistingProducts_Record.vbs yourOutput.msi
Unfortunately, it still takes two updates for the installer class to properly percolate to the installer. Presumably, this could be fixed by adding an even lower sequence number to RemoveExistingProducts
in the msi file, but I'm done fiddling with this for now.
Upvotes: 0
Reputation: 2780
You can add the custom action class (.dll) to the Setup project. You have to add the InstallerActions.dll to the Install and Commit actions.
To add the custom action
Upvotes: 5
Reputation: 20780
The settings paradigm doesn't work with installer classes because you are not in a running application context. You're being called via reflection from an msiexec.exe process running with the system account without any working directory context. People typically use Xml processing directly on the settings file to get around this behavior. You need to name the full path to the settings file because, again, you are running as a callback from an msiexec.exe process.
The custom action doesn't need to be a Commit custom action because all VS custom actions run after all the files are installed. The only time you need a Commit custom is action is when you run code that has a dependency on a file being installed into the GAC on WinSxS because they are not accessible until Commit time.
Upvotes: 1