Visual Studio 2008是否支持配置(调试/发行版)特定的引用? [英] Does Visual Studio 2008 support configuration (debug/release build) specific references?
问题描述
我有一个C + / CLI文件(用/ CLI编译的唯一文件)的本地C ++项目,我想添加一个C#DLL的引用。
I've got a native C++ project with one C++/CLI file (the only file compiled with /CLI), I'd like to add a reference to a C# DLL.
有调试和发布的单独版本,但我只能添加一个参考,适用于所有配置。参考搜索路径对话框包含一个警告,如果我尝试使用任何$ ConfigurationName类型参数,他们只会引用项目中的第一个配置。
There are separate versions for debug and release however I can only seem to add one reference which is applied to all configurations. The reference search path dialog box contains a warning that if I attempt to use any $ConfigurationName type parameters they will only ever refer to the first configuration in the project.
当前的想法是:
- 在一个解决方案下将两个项目加入到一起,并添加对项目我的理解是,Visual Studio然后将匹配配置。不太理想,因为我的项目和DLL是由不同的区域拥有。
- 一个项目调试(只有调试配置)和一个发布项目
在Visual Studio 2008中实现特定于配置的引用的任何更清晰的方法?
Any cleaner ways to achieve configuration specific references in Visual Studio 2008?
推荐答案
我通常做的是将所有项目的输出路径设置为相同的位置,具体取决于配置。例如对于发布构建,一切都进入/ path / to / Release并且调试到/ path / to Debug。然后我手动编辑项目文件以包含一个单独的目标文件,其中包含如下内容:
What I usually do is set the output path for all projects to the same location depending on the configuration. Eg for release builds everything goes into /path/to/Release and for Debug to /path/to Debug. Then I manually edit the project file to include a seperate targets file containing something like this:
编辑显示如何使用条件选择调试/用前缀
edit shows how to use conditions to select debug/release dll with a prefix
<-- file myDll.targets -->
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
<Reference Include="myDll_d">
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)' == 'Release' ">
<Reference Include="myDll">
<Private>False</Private>
</Reference>
</ItemGroup>
</Project>
然后在需要引用此dll的项目中包含目标文件:
Then in the project that needs to reference this dll the targets file is included:
<Import Project="myDll.targets"/>
由于 Private = false
msbuild won' t尝试复制任何东西,它只是寻找myDll.dll,并会在输出路径中找到它。
Because of Private=false
msbuild won't try to copy anything, it just looks for myDll.dll and will find it in the output path.
这不是特别干净,但工作。目标文件也可以修改为引用不同的平台(x86 / x64)。
This is not particularly clean but does work. The targets file can also be modified to reference different platforms (x86/x64).
你的第一个想法可能是最常用的,因为它需要更少的麻烦 - 项目应该在同一个解决方案(据我所知);
Your first idea is probably what is mostly used as it requires the less hassle - except indeed that the projects should be in the same solution (as far as I know);
这篇关于Visual Studio 2008是否支持配置(调试/发行版)特定的引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!