The development tasks I worked on the last few months where mostly focused on Office365 and (provider hosted) Apps. Since it is not necessary to have a local SharePoint farm for these tasks there is no need to be in a server OS. If possible I try to develop on the host OS of my laptop (Windows 8.1) instead of using a virtual server OS like Windows Server 2012.
Today was no different from that. Starting the day with launching visual studio and doing a test run, just before giving a colleague a demo and explanation about a provider hosted app. No changes were made since the last time it ran but still it gave an error: “Error occurred in deployment step 'Install app for SharePoint': The file exists. (Exception from HRESULT: 0x80070050)”. This didn’t tell me much about the cause, no files were added to the project. Trying to retract the app from the Office 365 site didn’t solve anything.
Not having much time to investigate led me into booting into a virtual machine with Windows Server 2012. Getting the sources and hitting F5, targeting the same Office 365 tenant, worked without any problems.
After the demo I went back to the host OS trying to find an explanation for the problem. I found some hints on the MSDN forums which led me to a user permission article on MSDN. This article states that it is necessary to run visual studio as administrator if you want to accomplish certain tasks. In my case I needed to debug some cloud services via the Azure emulator.
Running Visual Studio as administrator solved the problems I had with the deployment.
If you have the same problems and restart Visual Studio to run as administrator do not forget to shut down the Azure Emulator. If this is not done the emulator will keep on running with lesser privileges. Trying to post something to for example the Azure Queue in the emulator will cause an error.