.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.
참고URL : https://stackoverflow.com/questions/15666618/csproj-multiple-hint-paths-for-an-assembly
'program tip' 카테고리의 다른 글
모듈은 어디에서 가져 오나요? (0) | 2020.12.01 |
---|---|
JBehave와 Cucumber의 차이점은 무엇입니까? (0) | 2020.12.01 |
파이썬에서 int를 Enum으로 변환하는 방법은 무엇입니까? (0) | 2020.12.01 |
지연 로딩 vs Eager 로딩 (0) | 2020.12.01 |
메이크 파일 디버깅 도구 (0) | 2020.12.01 |