Edit: What I did to solve this:
Created a new NuGet package with the following nuspec:
<package>
<metadata>
<id>VIPSNuget</id>
<version>1.0.0.0</version>
<title>$title$</title>
<authors>Devedse</authors>
<owners>Devedse</owners>
<licenseUrl>https://github.com/jcupitt/libvips/blob/master/COPYING</licenseUrl>
<projectUrl>https://github.com/jcupitt/libvips</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Just the EXE file for VIPS</description>
<releaseNotes>First release</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>VIPS exe file</tags>
</metadata>
<files>
<file src="VIPS\*.*" target="tools" />
</files>
</package>
Placed all the .exe files in that folder.
Now from my ImageOptimizer I use the following code:
var userProfileDir = System.Environment.GetEnvironmentVariable("USERPROFILE");
string pathVips = Path.Combine(userProfileDir, Constants.VipsDir, "vips.exe");
Some Background
I'm currently working on an Image Processing library that needs to convert an Image from JPEG to PNG using the external tool named VIPS. (https://github.com/jcupitt/libvips).
Since I didn't want to include the binaries from VIPS in my own project I thought, let's make a NuGet package of it where the .exe file can be called from my code.
Steps I took
I create a new dotnet core solution using the 'dotnet new console' command. After that I created a directory named "VIPS" and pasted all binaries in there.
I then created a nuspec file containing the following XML:
<?xml version="1.0"?>
<package>
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>Devedse</authors>
<owners>Devedse</owners>
<licenseUrl>https://github.com/jcupitt/libvips/blob/master/COPYING</licenseUrl>
<projectUrl>https://github.com/jcupitt/libvips</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Just the EXE file for VIPS</description>
<releaseNotes>First release</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>VIPS exe file</tags>
</metadata>
<files>
<file src="VIPS\*.*" target="tools" />
</files>
</package>
I edited my .csproj file so that it only contained this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.0</TargetFramework>
<Version>1.0.4.0</Version>
</PropertyGroup>
</Project>
Problem
Whenever I run the 'dotnet pack' command now, everything seems to go fine:
But all the files from the VIPS directory are not included in my created nupkg:
(Reason why I chose tools is because in earlier versions of the dotnet framework / NuGet, I used tools like ILRepack that would be automatically installed in a tools directory which could then be called from a relative path of your deployed .exe file).
(Also see for example the nuspec code in https://github.com/gluck/il-repack/blob/master/build.gradle at line 92 where they also include the created .exe file in the 'tools' target)
Further investigation
What I then tried was to add all files from the VIPS directory into my csproj file and set the build action to Content.
All binary files now get included in the following 2 directories (so all duplicates which is also strange): vipsnuget.1.0.0.nupkg\content\VIPS\ vipsnuget.1.0.0.nupkg\contentFiles\any\netstandard1.0\VIPS\
However when I now include the NuGet package inside another project, and then pack that project it seems to also include all binaries in that package again too:
(All VIPS binaries are now placed inside: DeveImageOptimizer.1.0.0.nupkg\contentFiles\any\netstandard1.5\ and again in content\VIPS)
This isn't really desireable since the actual size of the DLL's in there should only be a few Kb's.
Another issue with this approach
I'm not actually sure if there's a good/better solution for this, but currently, when the NuGet package is restored, it will be extracted in %userprofile%.nuget\packages\vipsnuget...
So whenever I want to run a command against the VIPS.exe I need to point the Process.Start arguments to %userprofile%... . Is there a better way to do this? (E.g. find the place where NuGet packages are restored in code?)
What I would like best
Basically what I would like best, is to create a NuGet package where, if you include it, a certain directory will be copied to the build output of the project.
So something like: DeveImageOptimizer\bin\debug\VIPS...
If that doesn't exist
If there's no way to do that, I would like to hear what the normal approach would be for putting certain 'tools' inside a NuGet package and calling them from inside C# code.