How can I use a NuGet package to distribute an executable

We have several non .NET exes (like PhantomJs) that we execute from our .NET web applications via a class Process

.

I would like to bundle these exes into NuGet packages so that they can be reliably hosted in different environments (web apps, console apps, and unit tests) without having to pre-host every potentially required version in some magical place on every machine.

Is there a recommended approach for this in NuGet?

One way that works, but seems rather clunky, is to inject the EXE as a resource into the .NET dll wrapper and then extract it to the filesystem at runtime. I am wondering if there is an easier approach.

+3


source to share


1 answer


You can add the executable to your content

NuGet package folder . When the package is installed in the project, the executable will appear in the file as a file. From NuGet Docs :

The files in the folder are content

copied to the root of your application when the package is installed.

Think of the Content folder as the root of your Destination Application. For example, if I want the package to add images in the /images

Destination Application directory , make sure to put the image in the Content/images

package folder .



Then you can add a install.ps1

script to the NuGet package to set up the project to copy the executable to the output directory, as described in the answer to this question .

+2


source







All Articles