I'm putting together a template project in Visual Studio for use by my department. The project needs to reference some common libraries that are stored elsewhere in TFS. The problem is that the template may get used in a wide variety of locations, and I'm having trouble trying to reliably set up HintPaths to handle all locations.
The templated project needs to be able to find the common libraries both locally and in TFS, for use in builds. Currently, in our existing applications, the references look like this:
<Reference Include="Company.Common">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\Core Components\Libraries\Company.Common\Latest\Company.Common.dll</HintPath>
</Reference>
But the number of parents needed to traverse to get to the root can vary.
Instead of setting up 50 conditional paths for ../, ../../, ../../../, and so on, my first thought was to set up an absolute reference. Working Folders are standardized in our organization, so locally, the reference can always be found at C:\Projects\Core Components\...
But this won't work for server builds. So I'm thinking I need some sort of environment variable that works out to $/. I'm picturing something like this:
<Choose>
<When Condition="Exists('C:\Projects')">
<ItemGroup>
<Reference Include="Company.Common">
<HintPath>C:\Projects\Core Components\Libraries\Company.Common\Latest\Company.Common.dll</HintPath>
</Reference>
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Company.Common">
<HintPath>$(TFSRoot)\Core Components\Libraries\Company.Common\Latest\Company.Common.dll</HintPath>
</Reference>
</ItemGroup>
</Otherwise>
</Choose>
But I can't figure out how to accomplish that.
Update:
Eventually, we did set up an internal Nuget server. I suggest to anyone with the same dilemma to just tackle whatever red tape holds you back from setting up Nuget. We spent 3 years living with this hacky way of doing things and there was always some new wrinkle requiring manual intervention.