Interesting problem when using IVsSccEnlistmentPathTranslation

One of the less recognized features of TFS integration with Visual Studio, is that we track how selection changes in Solution Explorer and we update Team Explorer accordingly. The motivation is that when you use Team menu, to for example create work item, you want to do it in the most probable team project – team project that contains files that you were editing.

Of course in order to do it, we need to to translate path we get from IVsSelectionEvents into server path. The path we get is a URL, whenever you select a http website in solution explorer. This is where IVsSccEnlistmentPathTranslation comes in. It is Visual Studio service, which allows translation of project path to enlistment path and vice versa. The enlistment path is the physical path, used by the scc provider. The project path is the path (possibly virtual) that is stored in the solution file. So for example http://localhost/foo is a project path, and c:\wwwroot\foo is a enlistment path. So far so good? You can try it, it works great.

The problem is after you open solution from source control. If solution contains http website and there already exists website with this name. Website will ask you if you want to overwrite existing website or not. If you say no, it will create http://localhost/foo_1. However sln file stays unchanged and project path is still http://localhost/foo. The 10$ question is what kind of path you get from IVsSelectionEvents… Yes, it’s foo_1 🙂 The translation service does not have method that will handle it (it cares only about http://localhost/foo and c:\\wwwroot\foo).

The solution: just use something else. In our case I’m using __VSHPROPID.VSHPROPID_ProjectDir from the IVsHierarchy object that is provided by IVsSelectionEvents as well.

Skip to main content