Avatar of vizagboy
vizagboy

asked on 

Visual Studio setup project - handling Version number and ProductCode

We have a Visual Studio setup project. The version number format is x.x.x .
I have overridden BeforeInstall and AfterInstall handlers. The first install goes through smoothly. I tried a upgrade (changed RemovedPreviousVersion = true, incremented the VersionNumber). After changing the Version Number, it prompted me to change the ProductCode.
If I do not change the ProductCode, the upgrade works fine in my local PC (the changes made to BeforeInstall and AfterInstall for the upgrade can be seen). I also have a virtual PC where i try the same. There it complaints saying The Product already exists and cannot upgrade.
If I change the ProductCode, the upgrade works fine but the changes in BeforeInstall and AfterInstall corresponding the previous version.
How can i have the changes in Install reflect in the upgrade and have the application work everywhere?
.NET ProgrammingInstallation

Avatar of undefined
Last Comment
vizagboy
Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

You indeed have to change product code when you change the version. The problem with BeforeInstall and AfterInstall - you you have to provide more details about what exactly you did, and what does it mean that "changes in BeforeInstall and AfterInstall corresponding the previous version".


Avatar of vizagboy
vizagboy

ASKER

This is what i meant. I made a Version 1.0.0 MSI and in the BeforeInstall and AfterInstall handlers i have a messageBox ("1.0.0)". The install went through fine and there were no messageBox's displayed.
Then i upgraded to Version 1.0.1 and changed the messageBox to 1.0.1. During the upgrade, i received two pop up's with 1.0.0 and 1.0.0.  Didnt understand why it was picking up the old contents.
Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

Have you rebuilt the project with installer class before building the new version of the setup?

Where did you put custom actions with the output from the installer class project?

Avatar of vizagboy
vizagboy

ASKER

Hi,

I figured out that the issue is with the machine. The same application if i build on any other machine it works fine. The messageBox in handlers always reflect the current MSI file version's only.
But on the build machine they show the messageBox corresponding to old MSI. Tried adding a rudimentary installer class with very basic setup project and still it doesnt work on the build machine.
Any suggestions what could have gone wrong on the build machine?
Avatar of vizagboy
vizagboy

ASKER

Basically, on the build machine, if i dont change the Product Code when changing the version number, the upgrade works fine. But that does not work on any other machine. Something might have got corrupted with the build machine but am not sure how to figure it out.
Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

How about checking what I mentioned in the 1st comment. Are you sure you have successfully rebuilt the installer?


Avatar of vizagboy
vizagboy

ASKER

Thanks for patienty replying.
I am always doing a Clean, Rebuild All of the installer project first, then Rebuild All of the setup project.
Took a very simple problem,
1) Created a C# application with just a button in it
2) Added installer class to it with this change:
        protected override void OnBeforeInstall(System.Collections.IDictionary savedState)
        {
            System.Windows.Forms.MessageBox.Show("Ver is 1.0.301");
            base.OnBeforeInstall(savedState);
        }
3) Added a setup project,  added primary output of C# app and custom action. Version is 1.0.301
4) Rebuild C# app first and then setup project. Install went thro fine and popped up 1.0.301 during installation
5) Modified the Installer class messageBox to Ver is 1.0.303
6) Changed the version number in setup project to 1.0.303 and said Yes to change the product code.
7) While upgrading the new msi, it again prompted me the "Ver is 1.0.301" dialog.

Did lot of digging in..
The Product Code for 1.0.301 is {B2D0E1BB-A7A1-43BC-8C12-B11F2A3A115B} and the
product code for 1.0.303 is {7D04BC1D-C894-4A26-B535-22AC5CB8C25E}.

I gathered the install log and am attaching it. If you can search for the product codes, i think you can help me out.


msi-output.txt
Avatar of vizagboy
vizagboy

ASKER

Between steps 6 and 7, as you mentioned i did a rebuild All of install project first and then rebuild All of the setup project.
Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

In the install log, it's very hard to find something, because visual studio setup creates many its own custom actions, and we don't even know what is the name of custom action that calls your installer.

I would suggest this:
1. try to install 1.0.303 without upgrading 301. I.e. uninstall 301, then install 303 and see what message it shows. If it shows 301, then we will know that old code still somehow gets in the setup, and upgrading is irrelevant.

2. In order to be able to find this custom action in the log, I think the only way is if you in your installer class assign a value to some Installer's property. Installer analyzes all changed properties after each action and prints in the log the property that changed, that's how we can find it.

If you also upgrade the version of c# application for the new version of setup, is it upgraded during the installation?
Avatar of vizagboy
vizagboy

ASKER

I tried one, uninstalled 301 and installed 303 and the install was successful. I was able to see the msgBox for 303.
So far I never modified the AssemblyInfo.cs file. In you last point, are you referring to that file?
Are we supposed to manullay change the Guid and Version in AssemblyInfo.cs whenever the version number and ProductCode are changed?
Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

guid - no; version - yes, but you also can do it in project properties / application / assembly information.

By the way, you can even omit c# output from the setup - just installer output is sufficient, you can then build the setup project.

Back to the original problem - I think at this point, it's really hard to tell what's going on, there's no logic explanation, and it looks like a bug in visual studio. If you follow (2), then maybe we would be able to detect in the log where this action is called, and if the old version is already uninstalled by that time. Probably it's not, somehow. If you could narrow down this setup project to the very essence and upload it here, I could try to reproduce it, and maybe I would find some explanation. If the site does not allow you to upload visual studio filetypes, you can upload them at www.ee-stuff.com (or any place like rapidshare.com) and link here.
Avatar of vizagboy
vizagboy

ASKER

I dont have the source code with me right now. Will get to home and will upload it first thing in the evening. Please bear with me.
Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

I have created sample solution like you described, and it worked as expected. You can download it from https://filedb.experts-exchange.com/incoming/ee-stuff/7214-test.zip and compare with yours. It's already v.2, but I'm sure you will handle that.
Avatar of vizagboy
vizagboy

ASKER

Apologies for the delay. Thank you for the code snippet. I downloaded, ran it and worked fine. Then I chanced the Installer.cs version to 2.1 (messagebox) and changed the Setup project version to 2.1, changed ProductCode and was able upgrade it successfully. I noticed the installer code i have is different from yours. I uploaded my code to
https://filedb.experts-exchange.com/incoming/ee-stuff/7215-TestFrm3.zip .
Can you tell me why it fails?
Avatar of vizagboy
vizagboy

ASKER

Only difference i could see is, mine is C# app and have a exe rather class library in the main project.
Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

Quite likely, this is the reason. You are adding primary output from your project, and primary output is exe, not installer. I can't claim that I have full understanding of how installer class works with setup and deployment project and its custom actions; but according to "Walkthrough: Using a Custom Action to Display a Message at Installation" from V.S. Help, you should create separate class library project with installer class, and it's the primary output of that project is what should be specified in custom action. That's what I did in my sample project, and it worked. With your exe, this is something different, hence pretty much unpredicted.
Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

Quite likely, this is the reason. You are adding primary output from your project, and primary output is exe, not installer. I can't claim that I have full understanding of how installer class works with setup and deployment project and its custom actions; but according to "Walkthrough: Using a Custom Action to Display a Message at Installation" from V.S. Help, you should create separate class library project with installer class, and it's the primary output of that project is what should be specified in custom action. That's what I did in my sample project, and it worked. With your exe, this is something different, hence pretty much unpredicted.
Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

...though, here's one possibility: in your custom actions, you have added "primary output from testfrm3" to all phases. So, when you upgrade, it fires on the uninstallation of the previous version - which is what you see. In my sample project, it was only under Install phase.
Avatar of vizagboy
vizagboy

ASKER

I made a new setup project and just added primary output to the install phase and it worked fine.
But in my actual project I need to perform tasks on all three handlers (OnBeforeUninstall, OnBeforeInstall and OnAfterInstall). When i add the primary output to Install and Uninstall phases it failed by showing previous version's contents.
Let me create a class library and add the primary output to both Install and Uninstall phases.
Avatar of vizagboy
vizagboy

ASKER

Tried your first suggestion. Added Class library and then added Installer class to the class library. With install as the only primary output phase its working good but if i add the primary output to uninstall, it failed. Were you able to successful add primary output to the uninstall phase and override OnBeforeUninstall? Atleast i wanted the current handler of OnBeforeInstall to be called always even though the old handler of OnBeforeUnInstall gets called, thats fine.
Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

Yes, I see - when I added beforeuninstall, then it showed version 1 on before and after install of version 2. Will try tomorrow.


Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

After having spent some time on this problem, I can't explain it by anything but bug in windows installer. At first I thought that the trick was in incrementing the version of the installer class dll as well, but that did not help either. During the installation, installer correctly replaces the temporary dll it calls as custom action for the new version, and still it somehow manages to call the old one even though the old one does not exist already. This happens in both Installer 3.1 and in 4.

I will send this sample to someone in Installer team in Microsoft so maybe they look into this. I will also ask in newsgroup microsot.public.windows.msi, so it's seen by some very qualified people.

Back to resolving your problem - it looks like it's time to think about some work-around, so if you want to work in that direction, please let me know what the custom actions are supposed to do, and maybe we will find another way.
Avatar of vizagboy
vizagboy

ASKER

Yes, i agree with you. Basically this is the requirement. I have a config folder in the installation directory which will contain some user specific files. Before uninstalling, I am backing up the config folder to a temporary directory and am storing the location in a registry key. After installalation, i am copying back the config directory to the install folder.
ASKER CERTIFIED SOLUTION
Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of vizagboy
vizagboy

ASKER

Ok.  I was not an expert in custom actions and didnt know the complications before.  Let me think on that lines. How should i proceed with this question? I can give you the points and close this question, but how do you think you can communicate back to me if yo hear back from the microsoft folks or msi groups? Will you be able to update the question even after i close it?
Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

Posted in the newsgroup, you can monitor at
news://msnews.microsoft.com/

Avatar of vizagboy
vizagboy

ASKER

Thanks for all your help.
Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

> Will you be able to update the question even after i close it?

Yes. But I suggest that we instead keep it open for some time. If there's going to be some response in newsgroup, it will be soon. If not, I will then send it to installer group, which also will respond within a week. Then we can discuss the result here.
Avatar of vizagboy
vizagboy

ASKER

You have understood the issue clearly and have directed me to the problem. Its amazing you have constantly given immediate feedback for all my questions. Thanks much!!
Avatar of vizagboy
vizagboy

ASKER

I have closed the question at the same time you were typing the last response :-).
Let me open a related question and we can pick this up there.
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo