Deploying windows application in Visual studio 2010 Express - c#

I have developed a windows application on C# in Visual Studio Express 2010. Now I want to deploy it.
I used publish to deploy but when I run the project it get error on the form where I have used some external files which I am using for I/O operation, read and write files.
How do I resolve this error? I am also using one folder for files.

I'm a big fan of using WiX for installers - even if you've got Visual Studio Pro with the built in MSI creation tools
http://wix.sourceforge.net/
the benefit of WiX is that you can do most anything, from the super simple to very complicated. The tool is great b/c you can get started quickly and then move up (adding dialogs, etc) as your app gets more popular.
One trick for installers - consider using VMWare/HyperV, install a test OS then take a snapshot of the OS before you install your app. IF everything works, great - you're done. However if something isnt right, roll the OS back to the pre-install snapshot, fix the bug, and try it again.

Add those external files to the project
Right Click the external files in your VS Set the Build Action as Content
Copy to Output directory to CopyAlways
Then try deploying

That may be due Windows 7 UAC permissions. Despite the fact that current books, msdn and even the snippets in Visual Studio teach methods of file IO, most are not correct when taking UAC into consideration.
All of your file operations should take place in UAC safe zones such as
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
You cannot read or write to files in the C:\Program Files (x86) directories unless you have elevated your app to run with higher privileges.
If you install your application and right click the executable and select Run As Administrator and everything works the problem is UAC.
If you haven't coded around UAC limitations I highly recommend reading up on it. It will save many headaches down the road.
http://www.codeproject.com/Articles/17968/Making-Your-Application-UAC-Aware

Related

In-use files not updated by MSI-installer (Visual Studio Installer project)

I'm using the Visual Studio Installer Projects extension to build the MSI-installer for my application. However, my application is meant to be running at all times, and if it's open when the user is installing a new version of my software, the open files are not overwritten, and very little to nothing is actually updated (although there are no installer-errors).
I've found that using the installer project's "Custom Actions" to run a script that closes the application doesn't help, as none of the actions are called before the files are replaced.
Is there a good way to make sure the open/locked files gets terminated before the files are supposed to be overwritten?
We had this problem, and the solution we came up with was to create two apps; the user app and an updater app. The MSI installs both. Each app checks if the other needs updating and, if it does, closes the other app, downloads the other app's updater, runs it, then relaunches the other app. Additionally, each app monitors if the other app is running and, if it isn't, launches it.
It would be useful to know more about your application and how you are doing the upgrade because:
You will normally see a FilesInUse dialog saying that files are in use, prompting the user to shut them down, but not if the install is silent.
Visual Studio setups have no built-in support for shutting down and restarting services, so if your app is a service you'll need extra work.
Files that actually do need to be replaced will prompt the user for a reboot (if they are not previously shut down) in order to replace them at reboot time.
So if you're not seeing reboot requests or FilesInUse dialogs in a UI install then something else is going on. So you need to be sure that:
a. You are really doing an upgrade where the version of the setup project has been incremented, the UpgradeCode is the same (and the ProductCode changes when you increment the setup project's version). Your symptoms could be the result of the upgrade not working and you're seeing just a repair.
b. The definition of "new version" is that you have an upgrade as in a., AND, the file versions of the binaries have been incremented. The default overwrite rules for installs require incremented file versions, so if they haven't been incremented you'll see no updates, and Windows will not attempt to show FilesInUse dialogs or reboot because there are no files that need replacing.
This isn't a solution to the problem, but rather another solution; the one requiring the least work in the end.
I ended up not using 'Visual Studio Installer Projects' for my installer. Instead I looked to Advanced Installer, which just works with no issues. Things like this is taken into account, and custom actions allow for more options.
If your project is open source, you can write to them about a free open source "professional" license, equal to their "professional" plan, which is normally $399 (onetime purchase).
REBOOT: How are you installing this MSI? What command line? If you set REBOOT=ReallySuppress on the command line, you will not be prompted for a reboot even if one is required to complete the installation of the product.
msiexec.exe /i MySetup.msi /QN REBOOT=ReallySuppress
If you are using a distribution system I suppose suppressing reboot prompts could be standard behavior. Then your product files should be put in place after a reboot (PendingFileRenameOperations or perhaps some newer mechanism).
It is also possible that Visual Studio Installer Projects do something strange that I am not aware of.
Log: I would try to create a good log file for the install, to determine what is going on:
msiexec.exe /i C:\Path\Your.msi /L*v C:\Your.log
Log All MSIs: Personally I like to enable logging for all MSI installations - as described in the "Globally for all setups on a machine" section in the above link.
Interpreting an MSI log: interpreting a log file can be challenging sometimes. Here is an answer with some links to help with this.
Reboot Manager: Reboot management is a very complex topic, and Windows features functionality - in the form of the restart manager feature - to try to minimize the need for reboots, by instead shutting down and restarting applications as part of an installation in an "auto-magical" fashion (application listens for messages and shuts itself down gracefully when told to, and the system may restart the application after the install - if configured to do so).
Updating your application to comply with the restart manager is the only real fix for such problems that you see, in my opinon.
The section "Restart Manager" in this question tries to summarize how to implement such support (maybe just read the yellow section a bit down the page).
The Advanced Installer guys have a very nice, technical article about this:
How do I add support for Windows Restart Manager to my application? Also linked to in the link directly above - still worth a direct link here I think.
According to below link
https://social.msdn.microsoft.com/Forums/windows/en-US/0b40b367-3341-43d8-b82e-1ace546969f8/how-can-installation-stop-and-restart-existing-service-?forum=winformssetup
"There is no good support in VS installs to stop and start services. During install, the issue is that custom actions run after everything is installed so it's too late to stop a service that you are upgrading or replacing. Yes, they have names like "BeforeInstall" but they really are not before the install."

Publishing VisualStudio programs

Now I have a completed program, that needs to be deployed with some files. I would like to ask, if it is possible to deploy the program without the use of ClickOnce or other external tools, with the minimum amount of required files?
The program will run on a server, and will be updated locally, but since the program is installed per user, does that mean if I log in to the server with my user, a person that uses the direct path to the program will not find it? It also makes maintaining the program slightly more annoying, because when changes come, the current maintainer will have to always navigate to the xyz folder to edit one config file. How do I publish the program without ClickOnce or other tools?
Your options include:
Click once (which you don't want)
Visual Studio installer Projects
WiX Toolset
Other installers ...
Write an installer on your own (wouldn't recommend)
Just put the exe (and other needed files) in some directory and launch the program
Put the exe on a shared location and launch from there
You can redistribute as a set of files. However I would not recommend this approach. You force the person who deploys your program :
Choose location for the files
Remember this location when time to uninstall comes.
Handle updates and version management
Restore program functionality if any of the required files will get damaged.
You can use VS Setup project template, here's tutorial
Alternatively you can use free Wix installer, it has a bit of a learning curve but provides much more power to the developer.
You can do perMachine install both with VS setup project and with wix.

How do I uninstall a program with C#.NET with VS Express 2008

I have VS 2008 Express (.NET 3.5) and currently have no way to elegantly uninstall my program whenever I publish an update. Right now people are using the program outside of my network (so I can't point them to some intranet folder to check for updates, and checking an internet site is no good either). There are frequent updates (for reasons too complicated to go into here) and they constantly need to be using Add/Remove programs to uninstall then reinstall. Is there a way to have a Start Menu option to uninstall my program? Surely there must be, I'm a novice at C# (just moved from VBA) so I'm still learning the options. Thanks
Have you looked at 'Click Once Deployment'?
http://msdn.microsoft.com/en-us/library/t71a733d(v=vs.80).aspx
It would allow your users to get updates as they are released as well as uninstall through add/remove programs.
If you use full Visual Studio, then you can create a Setup project which will create an Install/Uninstall EXE for you.
If not, then I guess you'll have to write your own installer, or maybe add some batch files to install or uninstall your program.

What are the differences between MSI and EXE installers, and which should I choose? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What are the specific differences between .msi and setup.exe file?
I am working on an installer for a new version of my project (C#).
Previously, I've used Inno Setup to create .exe files for installing my projects on other computers in the workplace. While reading through some tutorials, though, I came across Windows Installer XML, which uses XML files to build a .msi installer.
My project will be available on a network share that all the employees have access to so they can install the software (I'm currently working on an update checker as well)
What are the major differences between .exe and .msi installers? Why would I want to chose one over the other? Would either make more sense given my specific environment?
I found some of the information at this question, but there was not a lot of information.
I wouldn't use WiX for a new project. I'd use an 'Installer Project' in Visual Studio to build an MSI. An installer project is much, much easier to put together.
Many exe installers are actually stubs or containers that hold an MSI, btw.
I guess you've checked out http://en.wikipedia.org/wiki/Windows_Installer?
MSI's give administrators the ability to restrict installs, rebase installs, change or add custom actions, automate installs/reinstalls/uninstalls, standard logging and switches. It just really integrates into a corporate IT environment ( http://technet.microsoft.com/en-us/library/bb742606.aspx ).
A custom installer may have many of those features, but that would depend on the installer package.
Most EXE installers available today are simply stubs to verify that the target machine has just enough support to launch an MSI stored within the EXE. They do basic windows version checking and Windows Installer version checking, then essentially invoke msiexec and let Windows Installer handle the rest.
For a very basic installation, the Installer Project in Visual Studio can get you by, but for just about any kind of real customization or tweaking you'll need a real MSI editor. We use WiX and love it - but it's a bear to learn. If you've got the cash you can invest in InstallShield - but that has it's own set of quirks.
MSI is configurable while EXE is not. I know this doesn't answer your question directly, but I thought I should point towards the ClickOnce technology.
MSDN: See example here.
Simply stated, a ClickOnce application
is any Windows Presentation
Foundation, Windows Forms, or console
application published using ClickOnce
technology. You can publish a
ClickOnce application in three
different ways: from a Web page, from
a network file share, or from media
such as a CD-ROM. A ClickOnce
application can be installed on an end
user's computer and run locally even
when the computer is offline, or it
can be run in an online-only mode
without permanently installing
anything on the end user's computer.
For more information, see Choosing a
ClickOnce Deployment Strategy.
IndigoRose's MSI factory is extremely powerful and much, much cheaper than InstallShield.
It uses WiX internally and allows you to modify the XML files in any way you like. The bootstrapper (.exe, if you add one) has a powerful scripting engine based on Lua to do... well anything.

How can I deploy my C# project?

How can I deploy a C# Visual Studio 2005 project so that I can run the application in another system? My project has a few dependencies and files that have to be integrated while deploying the project.
What is the best way to handle this?
You need to know what dependencies you have.
you need to have .Net framework installed
you have to explicitly install all dependencies that you used from the GAC on your target machine (some 3rd party components)
and then you just need to copy files from your \bin\Release folder
install all services, etc. if you have any
In the simplest cases only copying files should be enough.
Have you looked into ClickOnce deployment?
It's far from perfect, but for projects without a huge amount of overhead, it's generally good enough.
What kind of project?
Assuming it's a regular winforms application, just copy everything from either the obj\debug or obj\release directory to the new computer. Then run your executable
You can right click on the project file in visual studio and publish to a different location. This will build the site and copy it to the specified directory.
Also, if you need to do anything extra during the build, you can specify custom build actions on the build tab of the project's properties.
EDIT: now that I see you added that it's a windows application my answer doesn't matter. I'd try adding a setup and deployment project in visual studio to handle installing/deploying your windows application.
You more or less have three options (maybe 4?) as I see it.
Windows Installer
ClickOnce
Just distribute
the exe itself
In your particular case I would suggest ClickOnce as long as the project is not massive with too many dependencies.
For other alternatives.
The right answer depends on many criteria.
The simplest way to deploy is by copying files. Just put your .exe, the dependent .dll's, and the .config file in a directory and copy it onto the target machine. It's simple, but there are many restrictions to this approach:
It assumes that the target machine has the right version of the .NET framework installed
It assumes a certain technical competence on the part of the person installing the software.
The installation won't do basic things like create start menu items.
Publishing the program for ClickOnce deployment addresses a lot of these issues, but it's got its own set of limitations. I haven't used it much, so there are probably more than these, though these alone are pretty significant:
Programs are installed into the ClickOnce cache, not the Program Files directory.
If your program does anything outside of the ClickOnce sandbox, you have to deal with security elevation and code signing.
You can create a VS Setup and Deployment project and build an .msi file to install the program. The most obvious drawback to this is that it's complicated: .msi files can do many, many things, and the Setup and Deployment object model is complex, with documentation that is, let us say, fanciful. But there are things you can do with .msi installation that you can't readily do with other approaches, including (and certainly not limited to):
Cleanly uninstall the program through Add/Remove Programs.
Provide an actual UI for installation that lets the user decide where to put the program.
Support scripted installation via MSIEXEC.
Install components besides the program, e.g. databases, COM objects, etc.
Put components in the target machine's GAC.

Categories