15

We have several non-.NET exes (e. g. PhantomJs) which we execute from our .NET web applications via the Process class.

I'd like to wrap these exes into NuGet packages so that they can be reliably located in different environments (web apps, console apps, and unit tests) without having to pre-place each potentially required version in some magic location on the each machine.

Is there a recommended approach for doing this in NuGet?

One way that works but seems kind of clunky is to embed the EXE as a resource in a wrapper .NET dll, and then extract it to the file system at runtime. I'm wondering if there's a simpler approach.

ChaseMedallion
  • 20,860
  • 17
  • 88
  • 152

1 Answers1

10

You could add the executable to the content folder of the NuGet package. When the package is installed on a project, the executable will then appear as a file in the project. From the NuGet docs:

Files in the content folder are copied to the root of your application when the package is installed.

Think of the Content folder as the root of your target application. For example, if I want a package to add an image in the /images directory of the target application, make sure to place the image in the Content/images folder of the package.

You could then add a install.ps1 script to the NuGet package to configure the project to copy the executable file to the output directory, as described in the answer to this question.

Community
  • 1
  • 1
Adrian Hofman
  • 1,421
  • 1
  • 11
  • 24