Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use a NuGet package to distribute an executable

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.

like image 464
ChaseMedallion Avatar asked May 04 '15 19:05

ChaseMedallion


People also ask

Can you put an EXE in a NuGet package?

Some Nuget packages include executables in their tools folder. It is very easy to use these tools within Visual Studio because Nuget makes them available in the path of the Package Manager Console. However, they are very difficult to use outside of Visual Studio, especially in a build script.

How do I use a Nupkg file?

NUPKG files help developers fetch the latest packages from Nuget.org using NuGet Package Manager instead of manually downloading and installing the development packages. NUPKG files are built from NUSPEC files and, when fetched, install the package on user system.

How do I get files from a NuGet package?

on the toolbar of the Assembly Explorer window or choose File | Open from NuGet Packages Cache in the main menu . This will open the Open from NuGet Packages Cache dialog. The dialog lists packages from all NuGet cache locations on your machine. Use the search field in the dialog to find the desired package.


1 Answers

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.

like image 147
Adrian Hofman Avatar answered Sep 20 '22 20:09

Adrian Hofman