0

Is there a way to specify in .csproj file, to use different reference for DLL when my project is build localy and when build on TFS?

I want to share some DLLs between more solutions (do not want to copy DLLs to each solution's lib directory).

My local source structure is as follows

.\TfsProject
    .\lib
        MyShared.Dll
    .\Solution1
        .\Project1
        .\Project2
    .\Solution2
        .\Project1
        .\Project2

All Projects share relative path to MyShared.Dll

<HintPath>..\..\lib\MyShared.Dll</HintPath>

My problem arise on TFS Build server, where is source structure different from the local one.

I have tried to update .csproj files to use conditional statements, to use different HintPath localy and on TFS build server when referencig the MyShared.Dll. My condition is as follows

<Choose>
  <!-- Local HintPath -->
  <When Condition="'$(SourceDir)' == ''">
    <ItemGroup>
      <Reference ...>
        <HintPath>..\..\lib\MyShared.Dll</HintPath>
      </Reference>
    </ItemGroup>
  </When>
  <!-- TFS Specific HintPath -->
  <Otherwise>
    <ItemGroup>
      <Reference ...>
        <HintPath>$(SourceDir)\..\_build\lib\MyShared.Dll</HintPath>
      </Reference>
    </ItemGroup>
  </Otherwise>
</Choose>

Localy build passes, but I get The type or namespace name could not be found error on TFS build because it cannot find MyShared.Dll.

Any idea how can I fix this? Thanks!

mimo
  • 6,221
  • 7
  • 42
  • 50

2 Answers2

1

I would configure the workspace mapping for the TFS Build to match what you have locally, so the relative paths can resolve properly on the build server.

Dylan Smith
  • 22,069
  • 2
  • 47
  • 62
  • This was my original plan, but got an error when second solution was build. Build wanted to re-download shared lib folder, but it was already assigned to workspace created for solution 1, during first build. – mimo Oct 01 '15 at 11:30
  • 1
    make sure all your workspace mappings are mapped to something under $(SourceDir) and that shouldn't happen. – Dylan Smith Oct 01 '15 at 12:11
  • Yeah, but I want to avoid to have shared lib in each solution. I want it to be in one folder in source control and all the solutions should reference it. I would still need to distinguish, if the build runs locally (reference to shared folder is used, which is outside of $(SourceDir)) or on build server, shared lib can be mapped under $(SourceDir), but different HintPath need to be used in .csproj. But finally figured it out using $(MSBuildProjectDirectory) variable. Anyway, thanks for your suggestions. – mimo Oct 01 '15 at 13:53
1

Fixed my issue by specifying $(MSBuildProjectDirectory) and adjusting HintPath instead of $(SourceDir). Seems that $(SourceDir) was not recognized by build server as valid variable within .csproj.

List of available build variables:

https://msdn.microsoft.com/en-us/library/ms164309(v=vs.120).aspx

This question also helped:

List of MSBuild built-in variables

Community
  • 1
  • 1
mimo
  • 6,221
  • 7
  • 42
  • 50