grigoryvp
grigoryvp

Reputation: 42593

Is it possible to add path to .dll in Visual Studio 2010 property sheet?

I have a Visual Studio 2010 and a project that uses third-party library. This third-party librarys consists of header files, library files and .dll files. So, in order for my project to include header files and link with library files i created and added following property sheet to it:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <ClCompile>
      <AdditionalIncludeDirectories>
        C:\sdk\superlib\include;
        %(AdditionalIncludeDirectories)
      </AdditionalIncludeDirectories>
    </ClCompile>
    <Link>
      <AdditionalLibraryDirectories>
        C:\sdk\superlib\lib;
        %(AdditionalLibraryDirectories)
      </AdditionalLibraryDirectories>
    </Link>
  </ItemDefinitionGroup>
</Project>

My project succesfully compiles and links with library. But it is a problem: in order for my executable to run it needs a library .dll that is inside sdk bin folder. So if i hit F5 in Visual Studio it will complain that superlib.dll not found :(. Of course i can manually copy it to output folder of my project - but is it possible to somehow set path to .dll in .vsprops file so it is automatically used upon run and debug?

Upvotes: 1

Views: 1442

Answers (1)

Brian Kretzler
Brian Kretzler

Reputation: 9938

You can specify this by adding the .dll file to the @(None) item array, and setting a metadata value so that it is automatically copied to the output. Add the following to your props file.

<ItemGroup>
   <None Include="C:\sdk\superlib\bin\superlib.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
   </None>
</ItemGroup>

If you don't want this to show up in the solution explorer, add the Visible=false metadata as well,

<ItemGroup>
   <None Include="C:\sdk\superlib\bin\superlib.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      <Visible>false</Visible>
   </None>
</ItemGroup>

Upvotes: 3

Related Questions