Does Visual Studio 2008 support configuration (debug/release build) specific references?

柔情痞子 提交于 2019-12-01 22:45:50

问题


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.

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.

So my current ideas are:

  • Join the two projects together under one solution and adding a reference to the "project" rather then the DLL assembly. My understanding is that Visual Studio will then match the configurations. Not ideal as my project and the DLL are "owned" by different areas.
  • One project for debug (with only the debug configuration) and a release project (with only a release configuration) but that feels like a bodge.

Any cleaner ways to achieve configuration specific references in Visual Studio 2008?


回答1:


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>

Then in the project that needs to reference this dll the targets file is included:

<Import Project="myDll.targets"/>

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.

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



来源:https://stackoverflow.com/questions/7055985/does-visual-studio-2008-support-configuration-debug-release-build-specific-ref

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!