Create NuGet solution-level package to copy some files - nuget

I have a simple task, I want to install a nuget package to a solution and have it copy files to the folder structure but I don't want to modify the solution or projects in any signifcant way.
Currently I have a solution-level package but I can't seem to get it to copy any files anywhere. All it does currently is add a reference to .nuget\packages.config and a pointer in the solution file. This is fine, I just need it to copy files as well, the <Files> element doesn't seem to be doing it.

Solution-level packages have been deprecated as of NuGet 3 last October.
https://github.com/NuGet/Home/issues/522#issuecomment-98845250

Related

Install nuget package without content folder

I need to install a nuget package in my csproj and I would like to prevent the installation of all files contained in the "content" folder of the nuget package.
Is there any way to do it?
Yes, there is a way to do this. If you use project.json way of managing nuget dependencies, we do not modify your project, irrespective of the content in the content folder.

Should config files added by NuGet package be in source control?

We have a custom NuGet package which contains a DLL and a config file. We make use of NuGet package restore so our packages are not commit in to Perforce. When the package is installed to the solution it adds a reference to the DLL and the config file is included in the root of the project. Both of these are desirable, but should the config file be checked in to source control?
Our CI environment breaks when the file is not checked in, but the package has been downloaded correctly. It looks like this is the correct NuGet behaviour, but I'm not sure what the suggested best practice it is with regards to content files and how they should be treated in version control. Do all content files added from packages need to be checked in?
NuGet package restore will only restore files into the packages directory.
Files that are copied into your project when installing a NuGet package should be checked into source control since they will not be restored.

NuGet package update removes unchanged files

I created a nuget package (let's name it Web.Content) with lots of js, css and other content for my other package (named Web). In nuspec file I had file section
<file src="Content\**\*.*" target="content\Content" />
I made changes in some files from Content folder, then I created a new version of Web.Content package.
I have a project that includes Web and Web.Content packages. After a new version of Web.Content package was created I updated it in my project via nuget. When I try to commit changes of my project, SVN suggests me to commit all content of Web.Comment package.
As I understand, when nuget package was updated all target folder "content\Content" was deleted and copied from package again.
But I need SVN to trace only changes that were made in a couple of files, I don't want to see thousands of changed files because actually changes were made only in some of them.
How can I make nuget copy only changed files? Should I change my nuspec file or should I create some PS script for my package that will override delete'n'copy nuget package update behaviour?
It will be great to have some examples or links.
Tried with NuGet 2.6.40627.9000 and Tortoise SVN 1.7.7.
As far as I understand NuGet copies files during package installation using somу VS API. This API makes SVN think that the file was deleted and a new file was added(probably this happened because VisualSVN or AnkhSVN is installed).
So we decided to do the next steps:
Place our content items in our own folder which name differs from
"Content"(let's name it "fs_content") because the presence of such
folder in package triggers NuGet usual installation behavior, but
we don't need NuGet to install our content in usual way.
Write own install.ps1 script that copies our content files to
destination and put it into Tools package folder.
But after installing such package our content items did not appear where they should appear. My colleague googled some information in NuGet help - "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." We placed a dummy file into "Content" folder and Install.ps1 script began to copy our content from "fs_content" folder as we want.
Now SVN determines only changes made in some files correctly.

what purpose does 'package restore' serve?

i understand that nuget's package restore downloads and 'installs' the various required packages before building a project. but i can't work out what purpose this actually serves.
as far as i can tell, the 'installation' of a package during the package restore, isn't the same as a package's actual installation - for example, if you do the following:
install the jQuery package (NOTE that this adds jQuery script files to your project's 'Scripts' directory)
delete the added jQuery script files
delete the 'packages' directory (steps 2 & 3 simulate the state on a build machine, or other dev's machine)
do a build (triggering a package restore)
at this point the build states
2> Successfully installed 'jQuery 1.9.1'.
however, the jQuery package's script files are NOT added to the 'Scripts' folder, and the files are NOT added to the project.
this means that you have to check these files into source control anyway.
which also means that when you update this package, you have to manage adding/removing the new/old files (since different, versioned filenames are used). otherwise your 'Scripts' folder fills up with an endless history of versioned script files.
so, if you have to check everything in anyway, and you have to manually manage adding and removing files when updating, what exactly is the benefit of restoring the package on build? what purpose does this serve?
more to the point, why doesn't this serve the obvious purpose: automatically adding the package's files to the project?
Using NuGet Without Committing Packages to Source Control discusses the reason behind package restore.
Package restore means you do not have to check the packages folder into source control. Once enabled for your project it will download the packages and put them back into the packages folder at build time if they are missing. It will not, as you have found, add any package files to your project. In the case of jQuery all the files from the NuGet package are added to your project. Other NuGet packages however include one or more binary files.

How to create a solution-level NuGet package?

How do I create a solution-level NuGet package. That is, one that does not touch any projects, and is listed in .nuget\packages.config (not in any project-level packages.config files).
For example, psake and RavenDB.Server are solution-level NuGet packages.
I can't find anything in the docs for .nuspec files or nuget.exe that says anything about solution-level packages. I can't find anything special in the build processes of those two projects when they call nuget pack. In fact, I can't find a single search result at all about creating solution-level packages.
I found a brief comment from Phil Haack. It's from an issue on CodePlex:
We already support this. Just don't put any content in the /Content
folder nor in the /Lib folder. If your package only has contents in
the /Tools folder, the package will not get installed in the project.
Haven't had a chance to test this out, but it sounds like what you're looking for. A quick peek into the RavenDB.Server package (rename .nupkg to .zip) reveals a setup that is consistent with what Phil said in his comment. No content folder, no lib folder. Lots of files. The files are not in a /tools folder, so I think it's safe to presume that's not a requirement.