‘Cannot connect to the targeted site’ error in Visual Studio 2012 RC SharePoint Developer Tools when working with custom host headers
When working with the new Visual Studio 2012 RC SharePoint Developer Tools you get the ‘Cannot connect to the targeted site’ error message if you try to connect to a local site that is using a host header. Although it seems very limiting the good news is that there is a workaround.
Custom Host Headers on a development machines
When working on SharePoint projects you might be using custom headers to make it easier for yourself to navigate between all the different sites in your development environments. The easiest way for registering a custom host header is to add it to the hosts file (located in c:\windows\system32\drivers\etc) on your development machine.
Registering a custom host header allows you to create Web Applications and Host Named Site Collections that are not only easier to navigate to than sites without a host and using a random port number, but also allow you to test some scenarios. The latest is even more important with SharePoint 2013 given its support for multiple URLs for Host Named Site Collections.
‘Cannot connect to the targeted site’
Unfortunately if you try to create a new SharePoint 2013 project and will try to connect to a Site Collection using a custom host header (no matter if it’s under a Web Application using host header or if it’s a Host Named Site Collection) you will get the following error:
Cannot connect to the targeted site. This error can occur if the specified site is not hosted on the local system. SharePoint solutions work only with locally-installed versions of SharePoint Foundation or SharePoint Server. Remote development is supported only for apps for SharePoint 2013.
Should you bypass this error by providing the URL of the default site, you will get a similar error as soon as you will try to change the URL in the project’s properties:
Property value is not valid. Remote SharePoint site connections are not supported.
It turns out that this is a known bug that will be fixed in the future versions of the SharePoint Developer Tools.
As for now the workaround is to have the host mapped in the hosts file not to 127.0.0.1 but to your real IP address.
When you try to create a new SharePoint 2013 project or will change the URL of an existing project everything will work as expected.
I’d like to thank David Zhao, Mike Morton and Sean Laberee of the Microsoft DEVDIV team for providing a workaround for this issue.