Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhantomJS nuget package doesn't install .exe file inside .NET Core project

I want to install phantomJS nuget package for my .NET Core project. This nuget package contains an .exe file (phantomjs.exe). (C:\Users\.nuget\packages\PhantomJS\2.1.1\tools\phantomjs)

Building or publishing solution doesn't copy .exe file inside the bin or publish folder.

Do I have to add a specific configuration in my project.json to automatically copy .exe when I'll publish or build??

like image 742
Nicolas Law-Dune Avatar asked Aug 19 '16 09:08

Nicolas Law-Dune


People also ask

Where are NuGet packages installed .NET core?

The global-packages folder is where NuGet installs any downloaded package. Each package is fully expanded into a subfolder that matches the package identifier and version number. Projects using the PackageReference format always use packages directly from this folder.

Does .NET core use NuGet?

For . NET (including . NET Core), the Microsoft-supported mechanism for sharing code is NuGet, which defines how packages for . NET are created, hosted, and consumed, and provides the tools for each of those roles.

How do I download NuGet packages locally?

Open your file, and inside packageSources add a new local key following this structure <add key="local" value="path" /> . This path can be a relative or absolute from NuGet. config folder. Now you can install a package locally with dotnet add package and source option to local.


1 Answers

Currently PhantomJS nuget package (v.2.1.1) targets classic windows-only .NET projects; phantomjs.exe is included into 'tools' folder and on install nuget executes script (install.ps1) that adds 'phantomjs.exe' to the project with CopyToOutputDirectory=true option. Unfortunately install scripts are not supported for netcore projects; since PhantomJS nuget package doesn't include any managed assemblies, it can be installed for netcore project but 'tools' folder is ignored.

It is possible to use "script" section in project.json ("postcompile"/"postpublish" mentioned by @Pawel) to copy phantomjs.exe explicitly, but it seems there are no any acceptable way to resolve path to PhantomJS nuget package during build procedure. In any way, PhantomJS nuget package includes only windows PhantomJS build and it is useless if you planning to run your .NET Core project under Linux or OS-X.

Maybe it is better avoid using PhantomJS nuget for netcore projects at all, and create custom build script (executed with "postcompile") that downloads and extracts appropriate phantomjs build for your target runtime platform.

like image 124
Vitaliy Fedorchenko Avatar answered Nov 25 '22 06:11

Vitaliy Fedorchenko