I am working on creating a script that I can use to deploy my Azure Service Fabric Application to my local cluster or to a Azure hosted cluster. And I am running into an issue if I run the script twice. The Connect-ServiceFabricCluster command fails when my script is executed the second time. I can restart the PowerShell console, or PowerShell ISE and the issue is not seen again until the second call. This results in a cumbersome process to change the script.
If you've looked into the Deploy-FabricApplication.ps1 script that Visual Studio creates when you create an Azure Service Fabric Application, this code should look familiar as that is my source for what I used in my script.
The error message I see when I run the script a second time is:
My Local.xml Publish Profile, I've made no changes to it, it is the default file Visual Studio created when I create the project.
Steps I take when I see the issue:
Run script to deploy
Verify everything is working
Reset local cluster
Run script to deploy again
Script encounters error
Is there anything I missing as to not encounter the issue on a second run? I wonder if I'm missing a disconnect command as a restart would clear any state that is kept around, but I've not found anything that appears to be a disconnect from service fabric cluster command.
I did find this post as well on SO which appears to be the same error, but the path to reproduce the issue is different.