Failed to add NuGet package.

I created the NuGet libtidy package, which fits in the Team Services feed.

When I try to install through the NuGet console, I get an error

Failed to add link to 'libtidy'

I read this post where the OP has a similar problem, but I could not solve the problem - I tried:

  • Delete all folders inside the package folder and update
  • Running regsvr32 "C:\Program Files (x86)\Common Files\microsoft shared\MSEnv\VsLangproj.olb" from the extended command line
  • Running Uninstall-Package libtidy -force from the package manager console (this does not work because the package is not installed
  • git clean -dfx
  • clearing nuget cache
  • manually delete the libtidy directory in the .nuget directory

EDIT

Having done a little research, can this be due to the fact that libtidy.dll is not controlled by code? Infact is ANSI-C. In our application, we use TidyManaged as a shell that is managed and successfully installed through nuget. Currently, if we manually copy the libtidy.dll file to bin, it works fine, but it would be better if the build process pulled into libtidy.dll, possibly as part of the Tidymanaged install, which is not currently available.

EDIT2

 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; 

EDIT3

Edit 3 :

I AM

a) placing libtidy.dll and Install.ps1 in a directory named nuget-libtidy in the manifest generated by nuget spec

I have:

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

When I run nuget pack , I get the following warning:

 WARNING: 1 issue(s) found with package 'nuget-libtidy2'. Issue: Assembly outside lib folder. Description: The assembly 'content\libtidy.dll' is not inside the 'lib' folder and hence it won't be added as reference when the package is installed into a project. Solution: Move it into the 'lib' folder if it should be referenced. 

b) When we create the application, libtidy.dll is placed in the root of the project (and not in bin) and receives the following error in the output window:

 Added package 'nuget-libtidy' to 'packages.config' Executing script file <path>\nuget-libtidy\tools\Install.ps1'... Cannot add a link to the file libtidy.dll. There is already a file of the same name in this folder. At <path>\nuget-libtidy\tools\Install.ps1:7 char:5 + $project.ProjectItems.AddFromFile("libtidy.dll"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException Successfully installed 'nuget-libtidy' to <Namepace> 
+5
source share
2 answers

You probably get it

Failed to add link to 'libtidy'

because you have libtidy somewhere inside the lib folder. When you install the package, a link will be automatically added to this folder, and you cannot directly add a link to an unmanaged library.

If you have not already done so, you need to manually create your nuget package, and not execute it on a project or assembly. For this:

  • Create a folder named nuget-libtidy
  • Add libtidy.dll, TidyManaged.dll and everything you need to this folder
  • Open cmd and browse to the newly created folder.
  • Run nuget spec to create the default manifest Package.nuspec (you will need to add nuget to your PATH environment variable
  • Add the following xml to the nuspec file created immediately after the closing </metadata>

     <files> <file src="libtidy.dll" target="content" /> <file src="TidyManaged.dll" target="lib" /> </files> 
  • Adjust any other value you need.

You can do this, package and deploy the nuget package. You need to libtidy.dll copy to the output directory. This means that after installing the package you will have to go to the right-click on the \ libtidy.dll dependencies in visual studio, select the properties and set Copy to Output Directory to Copy Always .

If you do not want this to be done, you could make a few more settings in the nuget-libtidy folder and manifest file. Basically you need to create an Install.ps1 file that adds

 <ItemGroup> <Content Include="libtidy.dll"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> 

to the project file of the installed project.

Here is an example Install.ps1 that should do what you want:

 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; 

After the PowerShell script completes, add another line to the manifest file:

 <file src="Install.ps1" target="tools" /> 

Remember to run scripts on Windows 10 so that you set the execution policy. I would suggest running Set-ExecutionPolicy RemoteSigned . After starting in PowerShell, you will have to reboot the system.

At this point, you can pack and deploy.

EDIT

Typo is found in the Install.ps1 file. Line 3, $file1 = $project.ProjectItems.Item("libtidy.dll"); should be $file = $project.ProjectItems.Item("libtidy.dll";

+5
source

I once had a problem that I had to run VS with increased permission to install the nuget package. Something in common with our corporate security settings.

0
source

All Articles