代码之家  ›  专栏  ›  技术社区  ›  Maxime Rouiller

在Visual Studio中添加引用的hintpath

  •  33
  • Maxime Rouiller  · 技术社区  · 16 年前

    我知道我可以添加 海因特 到外部dll,以帮助Visual Studio/TFS在生成时查找该dll。

    我想知道的是…可以添加多个吗 海因特 ?

    例如。。。开发人员将它们的DLL放在一个地方,我们在服务器的另一个地方获取最新的这些DLL,因此需要多个 海因特 .

    你觉得呢,世界?

    5 回复  |  直到 10 年前
        1
  •  38
  •   Alex    12 年前

    对不起,你 不能 使用多个hintpath。Visual Studio/msbuild只接受 最后的 <HintPath> 并将忽略以前的任何定义。在VS2010和VS2012中确认。

        2
  •  14
  •   Community CDub    8 年前

    此答案不再有效。AS Sardaukar's comment 说, Visual Studio总是盲目使用最后一个hintpath . Alex's answer 支持这一点。


    好吧。这次我比StackOverflow快。我试着把它加上去,看起来效果不错。

    所以多个HintPath是可能的。

    当你有了这个:

    <Reference Include="System.ComponentModel.Composition.Codeplex">
        <HintPath>..\..\..\MEF2_Preview2\bin\System.ComponentModel.Composition.Codeplex.dll</HintPath>
    </Reference>
    

    您可以简单地添加更多提示路径,如下所示:

    <Reference Include="System.ComponentModel.Composition.Codeplex">
        <HintPath>..\..\..\MEF2_Preview2\bin\System.ComponentModel.Composition.Codeplex.dll</HintPath>
        <HintPath>D:\MEF\System.ComponentModel.Composition.Codeplex.dll</HintPath>
    </Reference>
    
        3
  •  8
  •   Michael Hablich    13 年前

    您可以为此使用环境变量。例如。

    <Reference Include="System.ComponentModel.Composition.Codeplex">
        <HintPath>$(PathToDLLs)\MEF2_Preview2\bin\System.ComponentModel.Composition.Codeplex.dll</HintPath>
    </Reference>
    
        4
  •  3
  •   Wolf5    10 年前

    使用条件可以:

    <Reference Include="TheAssembly">
        <HintPath Condition="Exists('..\My\Assembly\Path')">..\My\Assembly\Path\TheAssembly.dll</HintPath>
        <HintPath Condition="Exists('..\..\My\Assembly\Path')">..\..\My\Assembly\Path\TheAssembly.dll</HintPath>
        <HintPath Condition="Exists('..\..\..\My\Assembly\Path')">..\..\..\My\Assembly\Path\TheAssembly.dll</HintPath>
        <HintPath Condition="Exists('..\..\..\..\My\Assembly\Path')">..\..\..\..\My\Assembly\Path\TheAssembly.dll</HintPath>
        <HintPath Condition="Exists('..\..\..\..\..\My\Assembly\Path')">..\..\..\..\..\My\Assembly\Path\TheAssembly.dll</HintPath>
        <HintPath Condition="Exists('..\..\..\..\..\..\My\Assembly\Path')">..\..\..\..\..\..\My\Assembly\Path\TheAssembly.dll</HintPath>
        <HintPath Condition="Exists('..\..\..\..\..\..\..\My\Assembly\Path')">..\..\..\..\..\..\..\My\Assembly\Path\TheAssembly.dll</HintPath>
        etc...
    </Reference>
    

    将使用条件值为true的最后一个hintpath。

        5
  •  2
  •   Stephen Turner    10 年前

    将以下内容添加到项目文件底部的“注释掉的目标”部分之后:

    <Target Name="BeforeResolveReferences">
      <CreateProperty Value="YOUR_FIRST_PATH;YOUR_SECOND_PATH;$(AssemblySearchPaths)">
        <Output TaskParameter="Value" PropertyName="AssemblySearchPaths" />
      </CreateProperty>
    </Target>
    

    替代 YOUR_FIRST_PATH YOUR_SECOND_PATH 有你的路。

    重要的是,这会出现在以下行之后,否则您的设置将被覆盖:

    <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

    $(AssemblySearchPaths) 路径中字符串dll末尾的条目将覆盖正常分辨率。如果将其移动到开始位置,则首先尝试正常分辨率,并检查未找到的其他路径。正常分辨率包括 <HintPath> 因此,如果您的路径排在第一位,则无需删除它们。