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.
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.
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.
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.
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 theContent/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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With