Copy tools from nuget package to bin folder - nuget

I have some automated tests that are using Selenium WebDriver. Tests should run on Chrome so I need to have ChromeDriver.exe. I am using NuGet to download the libraries and found that the ChromeDriver could be downloaded as a package too (http://www.nuget.org/packages/WebDriver.ChromeDriver).
However, this package contains only ChromeDriver.exe in the Tools folder. I need to copy this file into the bin folder because tests need to find it. Is there some way to do the copy in a generic way (without specific paths), because in the folder where the ChromeDriver.exe is unpacked from package contains version number so I would need to change the paths when the new version will be used. Also I would need to do similar thing with the NUnit.Runner package.

You could probably use a post-build event. Then inside the event use copy/xcopy and move it into the bin folder after the project has successfully built.

Related

Nuget Package Without Lib-Ref-Content Folders

I have downloaded an open source project, made changes to it and then created a nuget package from this new code. The package actually functions as a post-build target. It just runs an exe. That is why it does not contain a lib folder. There is a tools folder and files are copied under this folder. The other folders are: build, buildCrossTargeting, package, _rels. .But when I try to install this local nuget package to a .net 4.6.1 project, I get the following error in Visual Studio:
You are trying to install this package into a project that targets
'.NETFramework,Version=v4.6.1', but the package does not contain any
assembly references or content files that are compatible with that
framework.
When I open and inspect the original nuget package downloaded from nuget.org, I see the same structure. But somehow it installs fine while this locally created one raises error.
What can be done about it?
With the information you provided, I can only guess (please see How to create a Minimal, Reproducible Example). My guess is that you changed the name (id) of the package, but didn't change the name of the target or props files in the build directory. As the docs say, the name of the targets and props file must match the package id exactly, so if you change the package id, you must rename those files.

Installing NuGet packages to custom folder in a project in Visual Studio 2015

I have a Visual Studio 2015 solution with many projects. For one of the projects I would like the files from NuGet to download to a specific folder in my project. For example, I intend to use Bootstrap and also Signalr. I would like Bootstrap to download everything into one folder in my application, and not create folders within my project root. For example, I have a folder called 'Libs' in the project and would like those libraries to use 'Libs' as their root folder. This is due to an external build solution that handles everything in the 'Libs' folder.
I've found these docs about using a NuGet.config folder for the solution, but this does not handle my problem. Any ideas?
As far as I'm aware, this isn't possible. Each Nuget package is written with specific instructions on how to install into a project. One of those instructions is where to put files, another example would be what transform to apply to the web.config. Nuget doesn't specify a way to modify these instructions. The only thing you could do would be to modify the packages yourself - download the .nupkg file and open it up as a zip file, you will be able to edit the folder structure from there.

Creating folder with contents in project root

I developed a tool that besides DLL requires a strong named folder with 2 files in solution. Using NuGet GUI I created the folder and populated with files, but when I install package, the only DLL created but folder with 2 files are not. How can that be fixed?
NuGet has a set of conventions that define certain folders inside the NuGet package that will result in different actions being taken when the package is installed or uninstalled.
In order for folders to be created inside the project, when the NuGet package is installed, the folders need to be inside a Content directory. If you look at the jQuery package, it has a Content\Scripts folder with files inside it. This Scripts folder will be created inside your project, along with its files, when you install the jQuery NuGet package.
\Content
\Scripts
\jquery-2.1.0.js

NuGet how to apply properties to files

I am creating NuGet Package. I have put two files in content folder, exe and config files that will be added when user installs this package.
In addition I would like to change VS project properties for these two files.
What do I need to do for that when building the package?
When you say "apply properties change" do you mean file system properties such last modified time, hidden flag, etc.?
If so there are a set of PowerShell scripts that are run (if they exist in your package) you can use to do this. It won't happen when you build the package, but it will run when somebody installs the package - which should have the same effect form the users point of view. You probably want either Init.ps1 or Install.ps1.
From Automatically Running PowerShell Scripts During Package Installation and Removal in the NuGet docs:
A package can include PowerShell scripts that automatically run when
the package is installed or removed. NuGet automatically runs scripts
based on their file names using the following conventions:
Init.ps1 runs the first time a package is installed in a solution.
If the same package is installed into additional
projects in the solution, the script is not run during those
installations.
The script also runs every time the solution is
opened. For example, if you install a package, close Visual Studio,
and then start Visual Studio and open the solution, the Init.ps1
script runs again.
Install.ps1 runs when a package is installed in a project.
If the same package is installed in multiple projects in a solution,
the script runs each time the package is installed.
The package must have files in the content or lib folder for Install.ps1 to run. Just having something in the tools folder will not kick this off.
If your package also has an init.ps1, install.ps1 runs after init.ps1.
Uninstall.ps1 runs every time a package is uninstalled.
These files should be located in the tools directory of your package.
At the top of your file, add this line: param($installPath, $toolsPath, $package, $project)
$installPath is the path to the
folder where the package is installed
$toolsPath is the path to
the tools directory in the folder where the package is installed
$package is a reference to the package object.
$project is a
reference to the EnvDTE project object and represents the project the
package is installed into. Note: This will be null in Init.ps1. In
that case doesn't have a reference to a particular project because it
runs at the solution level. The properties of this object are defined
in the MSDN documentation.
When you are testing $project in the console while creating your scripts, you can set it to $project = Get-Project

NuGet and nUnit automation

I have a VS project and in the project properties under the Debug tab I set:
Start External Program: D:\SolutionName\packages\NUnit.2.5.10.11092\tools\nunit.exe
Command Arguments: projectname.dll
This lets me start nUnit and run the nunits tests dll and when I start debugging the project.
Is there a better way? We use TFS and not everyone installs the solution to d: and the version number in the path where NuGet installs it changes periodically.
Was hoping to some how grab the text of the nunit.exe path from the path in the VS: Project : References section that was placed there by NuGet. This way I wouldn't have to change it for nUnit version changes and other TFS users wouldn't have to change it either.
Any ideas?
You might want to take a look at this:
http://lostechies.com/joshuaflanagan/2011/06/24/how-to-use-a-tool-installed-by-nuget-in-your-build-scripts/
If you're using NUnit in NuGet, then the runner will be in packages\NUnit(version)\, so you could probably use $(SolutionDir)packages\NUnit(blah) in the External Program command to run the version pulled from the NuGet package.
As Danny mentioned, install it to a relative (to your source code) tools folder via NuGet, ie
./tools/nuget.exe install Nunit.Runners -o ./tools
Then in your project configuration, just use the relative path.
I ran into the same issue. After a great deal of searching I found this question: Get NuGet package folder in MSBuild
Basically, you can create a project item containing a sort-of "wildcard" in the path name in place of the specific version number and then tell MSBuild to retrieve the relative path directory.