How to uninstall automatically while installing new version in msi file - c#

I have made a msi project for my software in VS2015. I have made a.Net based desktop application. My requirement is that I would like to handle 2 cases :--
1- If our software is installed already, and user try to install it, it should automatically un-install existing software and delete database file (created by my application).
2- If installed version is lower then it should only uninstall application and leave my database file as it is.
Now in my setup project I have added Custom actions for install and un-install where I have given path of my dll and set Installer Class property to true. In this dll I have made a class inherited from System.Configuration.Install.Installer and handle Install , beforeInstall, uninstall like below :--
public partial class SetupManager : System.Configuration.Install.Installer
{
public SetupManager()
{
InitializeComponent();
this.BeforeInstall += SetupManager_BeforeInstall;
//this.Committed += new InstallEventHandler(DarkMailInstaller_Committed);
}
private void SetupManager_BeforeInstall(object sender, InstallEventArgs e)
{
MessageBox.Show("In Install event");
}
}
Now in un-install, I delete DB. it is working fine if I am un-installing from control panel and it removes my DB file as well.
But if I want to upgrade my product, before getting hit in my override function Like install or BeforeInstall it shows error "Another Version of this product is already installed. Installation of this version can not be continue. To configure or remove the existing version of product, use add/remove program of control panel".
Now I have searched on internet and it seems if I update my package code or product version, it should be able to install over it. Now I have following issues :--
1- In VS 2015, I dont have any property in setup project where I can set product version or package code ?
2- I have tried to edit it using Orca but even then if I try to install edited MSI file (with updated version number, package code and product code), I am facing same error.
3- I dont know why this this error is coming before executing Before-install event ?
4- I have found "RemoveExistingProducts" would be helpful in this case. But I can not find this property / action in VS2015. Where can I find it ?
Can some body please help me to solve this issue ?

In a Visual Studio setup project it's the RemovePreviousVersions property of the setup project, in with the other properties like Manufacturer, Version etc.
Increment the setup version's project version, accept the changes.
Set RemovePreviousVersions to true.
The UpgradeCode needs to be the same, so don't change it.
Increment the file versions of the binaries you need to be updated.
If you select the setup project in solution explorer and do F4 you should see the relevant properties.
Don't worry about PackageCode because Visual Studio creates a new one with every build, as it should.
Visual Studio custom actions all run after the files have been installed (despite the "before" name), so there's nothing you can do to influence the course of the installation. In any case you don't need them.
What you get is an MSI that will install as a fresh install to new customers. It will also upgrade an older product as it installs, and the Windows Installer overwrite rules mean that a data file updated by the application will not be replaced.
https://msdn.microsoft.com/en-us/library/windows/desktop/aa370531(v=vs.85).aspx
The generated MSI will have a RemoveExistingProducts sequenced towards the end of the install. Basically you don't need to worry about the internals of PackageCodes and so on because Visual Studio hides them.

Related

Updating application using msi fails to update dll project reference

I am creating a setup msi using a Project Output (Say Project-A), which refers another project (Say Project-B).
When i update application using new msi, dll of Project-B does not get updated though latest build contains some changes in Project-B
Note: When i uninstall the application, dll of Project-B remains in installation folder( not deleted).
It's not clear what you mean by "update ... using new msi" but the way you upgrade using Visual Studio installer projects is to increment the setup project's version and accept the changes, which include generating a new ProductCode. RemovePreviousVersions also needs setting to true. This should help and is still relevant:
https://www.simple-talk.com/dotnet/visual-studio/updates-to-setup-projects/
In addition you must increment the file versions of files you need replacing - it's not enough that they are just different.

How to skip folder selection form when update installed application via Windows Installer setup project

As the title describes, I am trying to skip the folder selection form when update the installed application via setup project in visual studio(casue the user already selected folder path when they installed the app). I googled online and find a way to disable folder form: http://www.codeproject.com/Tips/437285/Visual-Studio-Deployment-Setup-Disable-Installatio. However, How to know if it is installation or upgrade? If we know it is upgrade, how to get the installation path?
Thanks in advance!
I do not find any approaches to skip that folder form. This should be the reason that many installer tools exist in the market. Since my app is very small, I simply disabled the folder selection dialog. For anyone who are interested, please check this URL: http://www.codeproject.com/Tips/437285/Visual-Studio-Deployment-Setup-Disable-Installatio
If you saved the original install location in the registry, for example by saving [TARGETDIR] in a registry item, then you can retrieve it during an upgrade. You find out you're doing an upgrade because it will set a property called PREVIOUSVERSIONSINSTALLED. The problem is that there is no way to wire it all up in a VS setup project. You want the browse dialog there (not deleted) but you want to skip it if PREVIOUSVERSIONSINSTALLED has been set, and there's no support in VS setup projects for that. You'd need to go into the ControlEvent table in the MSI file and figure out how to skip the browse dialog, as well as have the Back button skip over if necessary, and that's just very difficult.
What's the actual issue? Visual Studio upgrades are complete installs that uninstall the previous product and install the new one wherever the user wants, so why is it necessary to install in the same location as the previous install?

Visual Studio Setup Project not removing DLL

I have a problem regarding the Visual Studio Setup Project and uninstalling an application.
This is a very basic installer, installing an ApplicationLauncher.exe C# .NET 4.0 console application and an Application.Common.dll (a dependency of the application ApplicationLauncher.exe).
The installation is a success, copying both the exe and DLL into the program files folder C:\Program Files (x86)\Company\ApplicationLauncher\.
My problem comes when uninstalling the application (through the MSI) - the uninstall seems successful, however it leaves Application.Common.dll behind, and doesn't remove it as I would expect.
I've used ProcessExplorer to make sure nothing else is using the DLL, no explorer windows are open during the uninstall.
Is this the expected functionality and do I have to create a custom action to remove this DLL? Or have I done something wrong? :S
It seems I was able to fix this issue by renaming the solution and product name of the application, I'm not sure how this fixed it, but it did.
My only thoughts here is this traversed through to the installer, where the application installed into a different folder, thus not applying the same permissions to the DLL..
It's not expected, no. It will happen if you ever done any of the following with your setup and installed it:
Marked the file Permanent.
Marked the file SharedLegacyFile true.
These are project settings, but if you set either of them and do the install it will stay behind. You can unset them in the setup project but that's too late - you've marked that component permanent or sharedlegacy on the system. If you use a brand new system, like a fresh virtual machine, reset these values if they are set and rebuild the MSI and do the install/uninstall does it still happen?
I had the same problem. Then I have tried to install and unistall my app on Windows XP and that had worked.
Renaming the ProductCode is treating the symptoms not the cause. The problem occurs when the uninstaller doesn't remove the dll. The next install will use the dll again and can't remove it on an uninstall event because it's still used by the other program.
These steps hopefully solve the problem:
Install your Software
Open CMD (with admin privileges) and run:
msiexec /x {ProductCode} /L*V "C:\CustomPath\FileName.log"
The ProductCode can be found when hitting F4 on the Setup Project
Open the log file and search for the lines that look something like this:
Disallowing uninstallation of component: {6CEC09F6-9108-7062-A692-2BCBACEE3BD8} since another client exists
Disallowing uninstallation of component: {A0A0FA84-CC0D-C5C4-1F57-169788C4482D} since another client exists
Disallowing uninstallation of component: {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} since another client exists
All these components have to be removed from the registry by hand. To do this the GUID (e.g. {6CEC09F6-9108-7062-A692-2BCBACEE3BD8}) first has to be converted into a packed/compressed GUID (e.g. 6F90CEC6801926076A29B2BCCAEEB38D). I found a Website where one can run a script to do this. Find the following code on the website and replace the right side with the GUID from the log.
string inStrGUID = "{6CEC09F6-9108-7062-A692-2BCBACEE3BD8}";
Open the registry (as an administrater) and search (Edit -> Find...) for the compressed GUID (uasually it's somewhere in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\)
Delete the folder that is equal to the compressed GUID. The values inside the folder should be a path to the dll.
Once deleted select the parent folder (...\S-1-5-18\components) and hit Edit -> Find...
Repeat these steps (4-7) for all components from the log file.
It's also a good idea to delete all files still present in the original folder that weren't uninstalled.
Can one prevent this from happening?
I don't know. This really isn't that easy to reproduce. Some other post on SO have suspected the install/uninstall option in Visual Studio to be the cause of the problem but I have a different theory:
This bug might be the result of RemoveExistingProducts in InstallExecuteSequence in the Setup being executed too late and therefore not removing dlls at the right time. This bug is known for years and can be fixed by doing this. If you need help with Orca this explains how to install it.

Cant see the Recent updates after Replacing Existing files in setup project

I have created a setup project for Windows Application . I have set following property to replace the existing version with the new version.
RemovePreviousversion=True;
Productcode=change;
But when I run exe from new installed version. I cannot see my new updates. It gives me the output of previous version!
The whole Explanation is Here
I have RemovePreviousVersions set to TRUE and InstallAllUsers set to TRUE.
When I need to do a new release, I update the Version field with a new version number in the installer and VS prompts me to update the product code, to which I answer YES. I have verified that it does indeed change the product code, but the package code also gets changed with it (verified by diffing project files using sourcesafe).
The UpgradeCode never changes between versions.
My version number changes are of the form: "1.1.2" -> "1.1.3" for example (just in case that has anything to do with it).
So only 3 fields are different between builds: ProductCode, PackageCode, and ProductVersion.
When I've done all that, I build the installer.
When I install the new version (I always install for all users and always into the same directory), I have seen three different results at various times:
It will appear to in install the new version, but I really end up with the old files still there (and one instance in the add/remove programs).
I end up with 2 instances of the app in the add/remove programs, both with the same name, and both pointing to the same directory.
It will uninstall the old one first and then install the new one (what it is supposed to do).
It is very frustrating to explain to users that to be safe, they have to uninstall the old manually before installing a new release because I have to tell them "it doesn't always uninstall the old one like it is supposed to".
Any suggestions? Why isn't this working? What am I missing here?
I Found answer.
Also need to change AssemblyVersion and AssemblyFileVersion in AssemblyInfo.cs

c# Check if there is a file on server with specific name

I making a program and wanted to make an update function... So lets say I make one update and put it on my dropbox.. When someone click on update, the program will check if there any file with different name (no same version) on the server and if there is, then start to download it.. Is it possible?
And my second problem I installed my program on my computer but when start the installer again it says:
Another version of this product is already installed. Installation cof this version cannot continue. To configure or remove the existing version of this product use add/remove programs on the control panel.
I want when I run second time installer a confirmation message appear if he want to delete previous version to install this one (I need this for the update)
You could create a web service that provides an index / manifest of a directory that you want to synchronize. The web service could also provide methods for uploading and downloading the synchronized files and folders.
If you are using a Visual Studio Setup Project (.msi) you can simply change the installer version. Visual Studio sees the change and asks you if you want to change the product code. You would say 'yes'. The installer should then remove previous versions before installing the latest. You would also want DetectNewerInstalledVersion = true and RemovePreviousVersions = true.
Not sure if it works for this scenario but you may want to look at a ClickOnce deployment. It may solve both of your problems. ClickOnce Deployment

Categories