program tip

.csproj 어셈블리에 대한 다중 힌트 경로

radiobox 2020. 12. 1. 07:51
반응형

.csproj 어셈블리에 대한 다중 힌트 경로


SDK 배포 용 예제 코드를 패키징하고 있습니다. 배포에서 코드에서 SDK 어셈블리까지의 상대 경로는 빌드 머신과 다릅니다. 예를 들면 :

분포

csharp/bin/assembly.dll
example/ex1/ex1.csproj

기계 구축

foo/sdk/csharp/bin/assembly.dll
bar/baz/quux/ex1/ex1.csproj

내가 아무것도 움직일 수 없다고 가정하자. ex1.csproj둘 다 살펴 보도록 지시 수있는 방법이 있습니까?

../../csharp/bin/ ../../../../foo/sdk/csharp/bin/ 에 대한 assembly.dll?

C ++에서는 독립 실행 형 속성 시트에 종속성 경로를 넣고 SDK를 사용하여 다른 버전을 배포했습니다. 그러나 C #에는 속성 시트가 ​​없으며 전체 프로젝트의 두 가지 버전을 유지하고 싶지 않습니다.

여러 태그를 사용할 수 없다는 이 질문보았 <HintPath>으므로 동일한 동작을 근사화하는 다른 방법을 찾고 있습니다.


단 하나의 HintPath 만 사용할 수 있기 때문에 가장 간단한 방법은 다음과 같이 아주 좋은 Condition 속성을 사용하는 것입니다.

<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>

따라서 질문에 대한 답은 다음과 같습니다.

<Reference Include="assembly">
    <HintPath Condition="Exists('..\..\csharp\bin')">..\..\csharp\bin\assembly.dll</HintPath>
    <HintPath Condition="Exists('..\..\..\..\foo\sdk\csharp\bin')">..\..\..\..\foo\sdk\csharp\bin\assembly.dll</HintPath>
</Reference>

여러 조건이 일치하면 마지막 조건이 사용됩니다.


내 경우에 작동하는 해키 솔루션을 찾았으며 상위 디렉토리는 트리 어딘가에서 다를 수 있습니다.

<Choose>
  <When Condition="Exists('$(MSBuildProjectDirectory)\..\..\example')">
    <ItemGroup>
      <Reference Include="Assembly ...">
        <HintPath>..\..\csharp\bin\assembly.dll</HintPath>
      </Reference>
    </ItemGroup>
  </When>
  <Otherwise>
    <ItemGroup>
      <Reference Include="Assembly ...">
         <HintPath>..\..\..\..\..\foo\sdk\csharp\bin\assembly.dll</HintPath>
      </Reference>
    </ItemGroup>
  </Otherwise>
</Choose>

일반 속성 그룹에 다음과 같이 보조 경로를 추가합니다. csproj 파일에서

<PropertyGroup>
    <ReferencePath>..\..\..\..\..\foo\sdk\csharp\bin\</ReferencePath>
    ...
</PropertyGroup>

ReferencePath속성은 MsBuild를 실행할 때 지정하기위한 것이지만 이와 같이 잘 작동합니다.


이 솔루션을 문제없이 사용하고 있습니다.

<Reference Include="log4net">
  <HintPath>
     $(SolutionDir)packages\log4net.2.0.8\lib\net45-full\log4net.dll
  </HintPath>
</Reference>

여기에서 얻었습니다 : LeonidVasilyev의 힌트 경로 상대 답변 사용


You could subst the /csharp/bin folder into a drive (differently on each machine), for example X: and then reference X:\ or X:\bin on both machines, as the path will now be the same.


Simply add the build server location of the DLLs as a Reference path on the project. Seems to do the trick nicely and is very simple. Works only if you know the build server's folder of the DLLs.

enter image description here

참고URL : https://stackoverflow.com/questions/15666618/csproj-multiple-hint-paths-for-an-assembly

반응형