Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
648 views
in Technique[技术] by (71.8m points)

c# - .csproj multiple hint paths for an assembly

I'm packaging example code for an SDK distribution. In the distribution, the relative path from code to the SDK assemblies is different from the build machine. For example:

Distribution

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

Build Machine

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

Assume that I can't move anything. Is there a way I can instruct ex1.csproj to look in both

../../csharp/bin/ and ../../../../foo/sdk/csharp/bin/ for assembly.dll?

In C++ I'd put the dependency path in a standalone property sheet and distribute a different version with the SDK. But C# doesn't have property sheets, and I don't want to maintain two versions of the full project.

I've seen this question which states that I can't use multiple <HintPath> tags, so I'm looking for another way to approximate the same behavior.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The simplest way since only ONE HintPath can be used is to use the all-so-nice Condition attribute like this:

<Reference Include="TheAssembly">
    <HintPath Condition="Exists('..MyAssemblyPath')">..MyAssemblyPathTheAssembly.dll</HintPath>
    <HintPath Condition="Exists('....MyAssemblyPath')">....MyAssemblyPathTheAssembly.dll</HintPath>
    <HintPath Condition="Exists('......MyAssemblyPath')">......MyAssemblyPathTheAssembly.dll</HintPath>
    <HintPath Condition="Exists('........MyAssemblyPath')">........MyAssemblyPathTheAssembly.dll</HintPath>
    <HintPath Condition="Exists('..........MyAssemblyPath')">..........MyAssemblyPathTheAssembly.dll</HintPath>
    <HintPath Condition="Exists('............MyAssemblyPath')">............MyAssemblyPathTheAssembly.dll</HintPath>
    <HintPath Condition="Exists('..............MyAssemblyPath')">..............MyAssemblyPathTheAssembly.dll</HintPath>
    etc...
</Reference>

So the answer to the question would be this:

<Reference Include="assembly">
    <HintPath Condition="Exists('....csharpin')">....csharpinassembly.dll</HintPath>
    <HintPath Condition="Exists('........foosdkcsharpin')">........foosdkcsharpinassembly.dll</HintPath>
</Reference>

If multiple conditions matches, the last one will be used.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...