I am trying to create an MSI installer/uninstaller for my Windows project, consisting of a service, a couple of user-mode exes/dlls and some data files. I was able to use Visual Studio 2010 to compile an MSI package using its Setup Project. It works fine for installation, but uninstallation requires some additional steps before files are actually removed along with the registry settings.
So I was wondering, is there any way I can run a script (C#, or WSH JScript) before removing files/registry settings?
Yes, you can add as well scripts (VBS or JScript) to an MSI as C# or C++ custom actions in compiled MSI enabled Dlls, you can call .exe files, etc. There is a table called CustomAction and the Custom actions can be sequenced with the sequence tables, the most important are InstallExecuteSequence and InstallUISequence.
Working with custom actions is not so an easy task I think. If it is possible for you to ask experts, I would consider it.
Most times, when you want to add a custom action for uninstalling resources, there is maybe something wrong with your MSI.
4 of 5 custom actions one wants to add, are not necessary but can be replaced with correct MSI table entries.
Generally, I don't recommend using Visual Studio installer, because it gives you not very much control, and it is easy to make things wrong, especially for upgrading and more complicated task.
But if you still want to add a custom action here is some basic idea:
For example for starting a VB script you can add a custom action of type 38. Choose a name in the "Action" column, let the "Source" columns empty, and type the VB script code in the "Target" column:
E.g. with something like that you have an VB "interface" to the MSI properties like the newly invented "MYDIR_EXISTS" here.
on Error Resume Next
set filobj = Createobject( "Scripting.FileSystemObject" )
If filobj.FolderExists("C:\MyDir") Then Session.Property("MYDIR_EXISTS") = "True"
...
If you work with Visual Studio Installer you could consider adding the custom actions with a transform afterwards. Again this needs some MSI knowledge.
Me, personally, I would not work with script files for distributed setups, only if the setup is an infrastructural one for the same company. But it is a starting point.
Calling an compiled .exe with Custom Action type 34 or 50 would be an alternative.
Related
This question is a complement for the post How to change the output name of an executable built by Visual Studio.
After reading this post I did the following:
Firstly, I followed the answer for this post and I could define the executable file name successfully.
Now, I would like to know if instead of only define the name as "Demo.exe" as mentioned in the example post above, it would be possible to embed the version defined in AssemblyInformationalVersionAttribute or in AssemblyVersionAttribute in the built file, resulting in something like "Demo_v1.0.0.0.exe"?
I'm developing my application in C# WinForms, using Visual Studio Express 2017.
Why would you want to change the name of the executable? Whenever you try building a Setup for your application, you need to change the Setup to include the new file. And when you install an update, your Setup needs to know all versions of your executable in order to delete the old version. That's just not what you want to do.
If you want to keep all versions of the software for yourself, come up with a different solution, e.g. moving the executable into a folder which has the version number.
That said, I have done this for Setups, so customers can download different versions of the Setup. I did that using a commercial tool called Visual Build, but there are other build automation tools available. So, my answer is: set up a continuous integration / continuous delivery pipeline (CI/CD) and automate the step there, not in Visual Studio.
From the project properties, you can add Post build event command line to rename your exe
pseudo
Maybe you can create another console renamer.exe which reads version defined in AssemblyInformationalVersionAttribute or in AssemblyVersionAttribute of your app and renames it and then call that renamer.exe from Post build event command line
write a powershell script to rename the newly built exe and call that script from Post build event command line
I am working on a project where I need to run an action before installing a new version, this action is to check if there a product already installed and to uninstall it. I tried to add custom action in visual studio installer but I can't add a DLL file from the outside of the project so the action won't run before the installation. My application is a Microsoft office addin so that why I used visual installer because it is very simply and straightforward. Is there any another solution ?
Note : Changing product code and set DetectNewerVersion to true didn't work,
now I have two same product in Program and Features
Here you can find InstallExecuteSequence numbers. You just should put yours custom action in right place, for example you can set Sequence=750 - it will be run before CostInitialize.
Also here's video tutorial how to use orca.exe. It's amazing app to check and debug your msi. In your case you can check is your CustomAction in right place or you should change number, or even your custom action isn't working.
And about "I tried to add custom action in visual studio installer but I can't add a DLL file from the outside of the project so the action won't run before the installation". I can't get what do you mean, but seems that you can't add dll with custom actions. Here's tutorial about it.
Iam new at this topic so please forgive me if my question is not reasonable. Iam using an installer for 3 assemblies. One of those assemlies i have to change a value of Type column. My Problem is, i can't say, which one is the one i need to change to the value of it because they are refered to an action KEY. I dont know, what is the key for the assemly i wanna update it's value. I'm using for that the program super orca. as you can see in the screeshot, i have for each assembly an install, comit, rollback and uninstall row.
Also is it possible to write a query somewhere inside VIsual studio, so i dont have to edit manuelly every time i compile a new version?
Don't have answer to the first question (Orca editor) but for the Visual studio part, you have two possibilities
possibility 1 - if possible, in visual studio set up post build actions to change properties of assembly files on the project which is producing your assemblies; if changing properties here is also reflected in installer that you build then you are done.
possibility 2 - create custom action in setup/installer project; this custom action executes when installer is executed. Custom action need to have code to change property of assembly through/during installation. This doesn't change the properties in installer but it changes properties of installed assemblies. Here is the example on how to write custom action
a hack - for orca editor - given that there are only three assemblies, you could try changing property one at a time and execute installer to see if it changed property of the right assembly.
(Using VS 2010 with a Visual Studio Installer project.)
I have added a 'Checkboxes(A)' dialog to the 'User Interface' under the 'Start | Welcome' dialog and set a checkbox with the property set to "DESKTOPICON". The option is being displayed.
In the 'File System' the 'User's Desktop' has the condition property set to DESKTOPICON=1.
When I run the install on my VM the option appears to be ignored and the desktop shortcut under the User's Desktop list is always installed.
I looked at these similar posts but it does not seem to work for the desktop icon?
How do I specify Visual Studion Installer Conditions?
Visual Studio Deployment Project Optional Desktop Shortcut
Is it normal for the User's Desktop to ignore it's condition property or am I doing something wrong?
Visual Studio setup projects create only shortcuts to installed files. This type of shortcuts are linked to their target and share the same component.
Since in Windows Installer you can condition only components and features, you cannot condition a shortcut directly.
A common approach is to write a custom action which removes the shortcut. You can then condition the action instead of the actual shortcut or its folder.
Well, I know it's been a long time but today I faced exactly the same issue as mentioned. I wanted to try creating a windows installer in VS 2013 using "Installer Projects" extension thing and wanted to make a checkbox with condition whether create a desktop shortcut or not.
Like above, shortcut under User's Desktop was always installed.
After wasting almost 3 hours I found a workaround on the old Microsoft Connect feedback post: (which apparently was already dead for some time)
Ok I got this to work by adding the main file twice to the folder (the
file you are creating your shortcut to). I tie the shortcut to one of
the files and on that file I set the condition to CHECKBOXA1=1 so it
will only create that file and the shortcut if they check the the
"Create Shortcut" box. For the other file I set the condition to
CHECKBOXA1<>1 so it will create it when the check box is anything but
1 (not checked).
originally posted by Chancea on 7/1/2010
I tried to do it that way - it works as intended. Not really convenient whatsoever (can mix up the same looking names etc). For a really, really simple installer thing (which I needed) with an only additional feature, adding shortcut to desktop, it might be fine however.
Nevertheless I still think it only proves that this is just a port of an Installer Project from earlier versions of Visual Studio, now added by an extension.
The idea may be good and useful I think, but I wish they fixed just some of the Windows Installer project in VS issues and lack of features.
Like I said, it would be great option for people (... like me) who want to publish some pretty small and lightweight apps, and needs only some basic features from the installer like (optional desktop shortcut, adding to startup, installing some additional files etc etc).
Well, I guess the conclusion is that I'd just have to start learning WiX or try out the InstallShield
After another 2 1/2 years in VS2019: The problem remains that the shortcut created in the "User's Desktop" folder can not handle the condition imposed by the checkbox. Thus a somewhat simpler (but also not "clean") solution would be not to duplicate the exe (e.g. myApp.exe) like in Skippers solution (it did not work for me), but to create an additional myApp.bat file doing nothing but starting the myApp.exe.
The simplification consists in the fact that only a condition on the myApp.bat file is necessary, and no one on the myApp.exe file.
The following steps worked here:
Create a myApp.bat file doing nothing but starting myApp.exe, i.e. containing the single line "myApp.exe" (without the quotes). Of course, commandline parameters would be possible if necessary.
Put myApp.bat into the "Application Folder" of your installer project.
Set the condition on myApp.bat to CHECKBOXA1=1, meaning it is created only in case of the CHECKBOXA1 having been set.
In the "User's Desktop" folder of the installer project, create a shortcut to myApp.bat (Context menu "Create new shortcut"), give it the icon of your app ("Icon" property). Do not specify a condition. Here in my case (VS2019 on Win10) this resulted in a NOP action when the myApp.bat was not created (checkbox unchecked), and properly created the link on the desktop when myApp.bat was present (checkbox checked).
For this shortcut, you might wish to set the "ShowCmd" property to vsdscMinimized, to avoid the large command line window of the bat file.
I have made an application, which keeps getting updated frequently. So every time a change occurs, i've to include it's fresh builds to the setup and deployment program again and again. Is there any way to simplify the procedure? The files to be added are static in number and exist in a folder. I've heard we can write installer classes in c#, does my requirement has any thing to do with it?
I think ClickOnce doesn't suit my requirement because, for the first time i want it to run like a setup package, since it has some packages and some settings needed to be implemented on the user's machine at the time of install. Can click once help me with that? Also i want to run my application as an administrator and it references to many external dll files. So will it help my purpose?
I finally did it using clickonce deployment. I used content files to mark all the files i wanted to copy to the target computer and used clickonce deployment. Then i modified the way my program starts, so that i can lauch the installer script i wanted to run only when the app runs for the first time. Further i hosted it on IIS and had to change lot of MIME types and add new ones for the download to work over internet
Look into something called "ClickOnce" deployment. It automates a lot of what you're talking about.
EDIT: You can add custom installer actions to a ClickOnce project just like any other, to set up additional components and whatnot. As for permissions, ClickOnce will let you run as administrator if you so choose, but that sort of thing isn't recommended, and it might whine about it.
You can use ClickOnce (http://msdn.microsoft.com/en-us/library/t71a733d(VS.80).aspx) which simplify the deployment process.
Maybe you can also automate the build process using NANT (http://nant.sourceforge.net/).
HTH
Yes, you can do that.
I assume you want the client to update itself when ever there is a new version.
This needs a few changes in the client code. Essentially how it works is check for availablilty of new version at a predefined location. Update you new versions to this location. On the client side, show a message to the user if he/she wants to upgrade to the new version.
You can find a link to sample project out here and here.
You can add a Setup project in your solution inside Visual Studio and then add your other project(s) outputs, or static files to the Setup project as references. The Setup project will then detect your dependencies automatically and each time you do a Rebuild All (or you rebuild/build your Setup project) it will automatically include all the necessary files.
What type of project is it? In many cases, ClickOnce can do the job for you, at nominal effort.
Beyond that - you can usually hook your installer build into your build process; some tools will do this for you.
Installer classes run at the client - so I don't think they relate to your build process...
I would flag the files as Content in their respective properties and then in the deployment project right click the project, go to File System and then right click the folder, click Add and select Content Files from the dialog box. This should copy the newest files over every time you build the deployment project.