In an upgrade scenario, before you upgrade (or uninstall old/install new) the MSI you must undeploy the existing application. These steps are covered here.
Regarding complete automation of deployments, I recommend that you start here (and reference this post too).