jap*_*iss 61 c# msbuild csproj visual-studio-2010
我正在打包SDK发行版的示例代码.在分发中,从代码到SDK程序集的相对路径与构建机器不同.例如:
分配
csharp/bin/assembly.dll
example/ex1/ex1.csproj
Run Code Online (Sandbox Code Playgroud)
构建机器
foo/sdk/csharp/bin/assembly.dll
bar/baz/quux/ex1/ex1.csproj
Run Code Online (Sandbox Code Playgroud)
假设我无法移动任何东西.有没有办法可以指导ex1.csproj两者兼顾
../../csharp/bin/ 并 ../../../../foo/sdk/csharp/bin/为assembly.dll?
在C++中,我将依赖路径放在一个独立的属性表中,并使用SDK分发不同的版本.但是C#没有属性表,我不想维护整个项目的两个版本.
我已经看到这个问题表明我不能使用多个<HintPath>标签,所以我正在寻找另一种方法来近似相同的行为.
Wol*_*lf5 87
由于只能使用ONE 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>
Run Code Online (Sandbox Code Playgroud)
所以这个问题的答案是这样的:
<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>
Run Code Online (Sandbox Code Playgroud)
如果多个条件匹配,则将使用最后一个条件.
jap*_*iss 20
我找到了一个适用于我的案例的hacky解决方案,其中父目录保证在树的某个地方不同:
<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>
Run Code Online (Sandbox Code Playgroud)
小智 8
我正在使用这个解决方案,没有任何问题:
<Reference Include="log4net">
<HintPath>
$(SolutionDir)packages\log4net.2.0.8\lib\net45-full\log4net.dll
</HintPath>
</Reference>
Run Code Online (Sandbox Code Playgroud)
从这里得到它: 使用 LeonidVasilyev 的提示路径相对答案
将以下辅助路径添加到常规属性组.在csproj文件中
<PropertyGroup>
<ReferencePath>..\..\..\..\..\foo\sdk\csharp\bin\</ReferencePath>
...
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
该ReferencePath属性旨在在执行MsBuild时指定,但它可以正常工作.
| 归档时间: |
|
| 查看次数: |
24016 次 |
| 最近记录: |