lee*_*d00 39 c# dll visual-studio-2010 release-management
我现在为Visual Studio 2010/C#下载了许多第三方库(dll),我注意到在他们的发行版\ bin目录中,它们通常有两个版本Debug和Release.
有没有办法将这些库添加为项目的引用,但是使用Release构建(当我构建版本时),并使用Debug构建(当我调试时)?
Waf*_*fle 65
<Reference Include="MyLib">
<HintPath>..\lib\$(Configuration)\MyLib.dll</HintPath>
</Reference>
Run Code Online (Sandbox Code Playgroud)
PHe*_*erg 37
您可以手动编辑csproj文件,在包含引用的ItemGroup上设置Condition属性.
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<Reference Include="MyLib">
<HintPath>..\..\Debug\MyLib.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Release'">
<Reference Include="MyLib">
<HintPath>..\..\Release\MyLib.dll</HintPath>
</Reference>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅此文章.
正如原始问题所述,如果您使用Release-和Debug-文件夹,WaffleSouffle的答案肯定是最好的.
似乎还有另一个选项并不那么明显,因为VS(VS2010)在编辑csproj文件时没有在IntelliSense中显示它.
您可以将条件添加到HintPath元素.像这样:
<Reference Include="MyLib">
<HintPath Condition="'$(Configuration)'=='Release'">..\lib\MyLib.dll</HintPath>
<HintPath Condition="'$(Configuration)'=='Debug'">..\lib\Debug\MyLib.dll</HintPath>
</Reference>
Run Code Online (Sandbox Code Playgroud)
我在http://blog.vivekrathod.com/2013/03/conditionally-referencing-debug-and.html上找到了Vivek Rathod撰写的一篇文章,描述了上述方法.
我检查了项目文件的XMS Schema文件:C:\ Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild\Microsoft.Build.Core.xsd和:C:\ Windows\Microsoft.NET\Framework\v4 .0.30319 \的MSBuild\Microsoft.Build.Commontypes.xsd
我看不出Condition是HintPath-element支持的属性,但它似乎确实有效.....
编辑1: 这不会使参考在Visual Studio中显示两次,这是接受的答案的问题.
编辑2: 实际上,如果省略HintPath,Visual Studio将查看项目输出文件夹.所以你可以这样做:
<Reference Include="MyLib">
<!-- // Removed HintPath, VS looks for references in $(OutDir) -->
</Reference>
Run Code Online (Sandbox Code Playgroud)
搜索顺序在文件Microsoft.Common.targets中指定.
请参阅:
Visual Studio中的HintPath vs ReferencePath
归档时间: |
|
查看次数: |
13116 次 |
最近记录: |