.csproj程序集的多个提示path

我正在打包SDK分发的示例代码。 在发行版中,从代码到SDK程序集的相对path与构build机器不同。 例如:

分配

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

build立机器

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

假设我不能移动任何东西。 有没有一种方法,我可以指示ex1.csproj看在两个

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

在C ++中,我会把依赖path放在一个独立的属性表中,并用SDK分发不同的版本。 但C#没有属性表,我不想维护整个项目的两个版本。

我见过这个问题 ,说我不能使用多个<HintPath>标签,所以我正在寻找另一种方法来近似相同的行为。

因为只有一个HintPath可以使用的最简单的方法是使用这样的all-so-nice 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> 

我发现了一个适用于我的情况的黑客解决scheme,其中父目录保证在树的某处不同:

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

将以下path添加到常规属性组中。 在csproj文件中

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

ReferencePath属性是用来在执行MsBuild时指定的,但是它可以正常工作。

您可以将/csharp/bin文件夹/csharp/bin为一个驱动器(在每台计算机上不同),例如X:然后在两台计算机上引用X:\X:\bin ,因为path现在是相同的。

只需将该DLL的构build服务器位置作为项目的引用path添加即可。 似乎很好地做的伎俩,是非常简单的。 只有在您知道构build服务器的DLL文件夹时才有效。

在这里输入图像说明