3

I have an application which uses an unmanaged library libtidy.dll. In our code are using a wrapper TidyManaged to use it.

We want to pull in libtidy from our Team Services private package feed for it to be placed in the bin directory

To do this I am creating a NuGet package as follows:

  • Create a directory libtidy-managed
  • Put both libtidy.dll and TidyManaged.dll into the new directory
  • Run nuget spec from this directory, with the following files

Package.nuspec:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>libtidy-tidymanaged</id>
    <version>1.0.0</version>
    <authors>Name</authors>
    <owners>Name</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Libtidy TidyManaged</description>
    <releaseNotes>Libtidy TidyManaged</releaseNotes>
    <copyright>Copyright 2016</copyright>
    <tags>Libtidy TidyManaged</tags>
  </metadata>
  <files>
      <file src="libtidy.dll" target="content" />
      <file src="TidyManaged.dll" target="lib" />
      <file src="Install.ps1" target="tools" />
  </files> 
</package>

Install.ps1

param($installPath, $toolsPath, $package, $project)

$file = $project.ProjectItems.Item("libtidy.dll");

If ($file -eq $null)
{
    $project.ProjectItems.AddFromFile("libtidy.dll");
    $file = $project.ProjectItems.Item("libtidy.dll");
}

$file.Properties.Item("CopyToOutputDirectory").Value = [int]1;

I then create the package using nuget pack and reference the new package in a local nuget feed.

When I build the solution libtidy.dll is placed in the root directory, instead of the bin directory

  • When I look at the properties of libtidy (in the root directory) after building, Copy to output directory is set to Copy always
  • When I look at the project properties, under the build tab, the Output path is set to bin\

Can anyone see what I am doing wrong?

Note: This question is a follow up from this Stack Overflow question - the user from the accepted answer says everything should work, but I am still getting this problem.

As far as I can see, I am following his instructions to the letter...

Community
  • 1
  • 1
Vinyl Warmth
  • 2,226
  • 3
  • 25
  • 50

1 Answers1

2

According to your steps, I successful copy the libtidy.dll to the bin directory after build the solution. The libtidy.dll in the root directory is not copied when build the solution. It should be added when you install the package. Because the libtidy.dll is an unmanaged dll, which could not reference directly in Project’s Reference. We often reference this type dlls through add them in the project directory.

After build your solution, please check the bin directory, there should be also has a libtidy.dll, which is copied when your solution build. If there doesn’t has this dll, please check your step2, make sure you are put the libtidy.dll, TidyManaged.dll and Install.ps1 file in the same directly. And the Project’s Output path should be “bin\Debug”.

Following is my package structure, please compare it with your package. enter image description here

Weiwei
  • 3,674
  • 1
  • 10
  • 13
  • Thanks for your reply. I notice that `libtidy` is now in the bin directory as expected after the script executes. Could you advise how to remove `libtidy` from the root directory, using the powershell script? (I have never really used powershell) – Vinyl Warmth Sep 20 '16 at 10:47
  • 1
    I'm afraid that we could not remove libtidy from the root directory. Because it is an unmanaged dll, we need to reference it by add it to the root directory. And the bin folder is would be cleaned when you rebuild your project. If the libtidy removed from root directory, when you rebuild your project, the libtidy will not copy to the bin folder. – Weiwei Sep 21 '16 at 01:30