We are looking to use Nuget to share code between repos.
I have created a Nuget package which contains all of the source code in a specified sub directory.
In 7Zip I can explore it and see all of the files are present.
I need to import it into another project, maintaining the directory structure so the project can build, be debugged etc.
So I have:
../repo/applications/CommonCore
But CommonCore comes from the imported nuget package.
When I import this Nuget package no files seem to be present and there is no obvious way of controlling which directory it would go to.
I have read about using the contentFiles tag to specify all of the source files but this is infeasible for me as there are hundreds of files in various subdirectories so I attempted to use a format like:
<contentFiles>
<files include="Fabric\*.*" buildAction="Content" copyToOutput="true" />
</contentFiles>
and
<files>
<file src="*.*" target="contentFiles\Fabric" />
</files>
But this has not helped.
Am I misunderstanding how Nuget works? Or have I just implemented it incorrectly?
NuGet packages are designed for binary dependencies, so the normal thing to do here is build the code from one repo, publish the resulting binaries (not the source code) in a NuGet package, then reference that package from your other project.
You can include whatever you like in a NuGet package so it is possible to add source files, but trying to use them as a way of doing source dependencies isn't what they're designed for.
Related
I have multiple projects in a added in multiple solutions and at different directory levels. I use packages.config to maintain list of dependencies.
On nuget restore for a solution through command line, packages folder is created in the same directory as solution file and gets all dependencies are downloaded. Now there are some projects added as reference which are also present in other solutions. So projects refer different packages folder. On restore only 1 packages folder is created and so some projects referring packages at other location, do not get their packages restored.
Is there any way one can get all dependencies in multiple packages folder in different directories?
You can create a NuGet.Config file with a repositoryPath which overrides the default behaviour.
<configuration>
<config>
<add key="repositoryPath" value="packages" />
</config>
</configuration>
The path is relative to where the directory the NuGet.Config file exists.
Note that the location of the NuGet.Config file should be in a directory that is the same or above the solutions. Whilst you can have multiple NuGet.Config files, it will probably be simpler to have one at the root directory of your solutions. For example:
/Your/Projects/Test/NuGet.Config
/Your/Projects/Test/MySolution.sln
/Your/Projects/Test/Another/MySolution2.sln
Also note that you would need to reinstall the NuGet packages in the projects, or at least fix the reference paths, since they will now be using a different packages directory and will be incorrect.
I have created a nuspec file for my solution. The solution has a few empty folders.
I have downloaded the latest nuget.exe from https://docs.nuget.org/consume/command-line-reference
However when I run my nuget pack command the empty folders are not being included. Looking at the documentation for the pack command, I am interpreting the fact that empty folders are included by default because of this flag:
ExcludeEmptyDirectories: Prevent inclusion of empty directories when building the package.
Unfortunately I am not able to get the pack command to include my empty folders.
My files structure is similar to
Root
Folder1
Folder2
Folder3
Folder1 and Folder2 have content files within them, but Folder3 is empty
My nuspec file defined as follows:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Package_7.2_140526</id>
<version>7.2.140526</version>
<title>Package 7.2 rev 140526</title>
<authors>My Company</authors>
<owners>My Company</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A vanilla website</description>
</metadata>
</package>
I have not included individual files because I want the nuget pack to include everything. While my example is only of 3 folders there are significantly more than than.
This is the nuget command I am running from the command line
nuget pack "c:\Projects\Package 7.2 rev 140526\Packagee 7.2 140526.nuspec" -OutputDirectory c:\Projects -NoPackageAnalysis
When that did not work I tried with the -ExcludeEmptyDirectories flag just incase
nuget pack "c:\Projects\Package 7.2 rev 140526\Packagee 7.2 140526.nuspec" -OutputDirectory c:\Projects -NoPackageAnalysis -ExcludeEmptyDirectories
But it still will not include the empty folder.
What needs to be done to get the nuget pack command to include the empty folders?
Update
I used the Nuget Package Explorer to add the empty folders to the solution and then looked in the modified nuspec file. It appears that the only way to include empty folders within nuget is to have a file entry as
<file src="folder3\_._" target="folder3\_._" />
And then have a postdeploy.ps1 file to delete all the files named "_._"
So it appears that will always have to specify the files.
Ps. I tested it with the following structure
\Folder3\Folder4.
If folder4 is empty then folder3 and folder4 are not created unless you include the "_._" file
But if there is a way to include empty folders without having to resort to _._ file then want to know, especially if the blank folder is nested as it is easy to get excluded
Yeah, it seems this is an issue that has a shady status of whether it is solved or not and how. There are some issues in the Nuget Github about this, but I coulnd't get a clear picture of what is the status.
Summary is there is a parameter for the nuget 'pack' command that is called -ExcludeEmptyDirectories that in reality is supposed to do the opposite of what it is called, but it doesn't work either what I could test.
See
https://github.com/NuGet/Home/issues/3009
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.
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.
I am trying to work out how NuGet knows what packages it needs to restore (and how it knows where to find them) in the case that they are not present locally (i.e. when the packages have not been committed to source control).
I can see in the solution I have a .nuget directory but that basically just contains the NuGet.exe. There's a packages.config in each project, that looks promising, that contains the following (shortened for clarity);
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="2.2.1" targetFramework="net40" />
</packages>
I was expecting to see a URL pointing to the source of the package. So if Nuget just uses the package id string, how would it know what to do if I had multiple package sources that both list available the same package Id. Is it just through the priority in the package sources?
I ask because I have a package from a local source, I deleted the packages and disabled the package source, cleaned the solution and rebuilt. It worked when I expected it would fail.
Many thanks.
There are 2 questions in your post, so I'll try to address one by one:
How NuGet knows what packages it needs to restore?
As you guessed, Nuget uses the .Nuget folder to automatically install missing packages. Inside the .Nuget folder, there is a file named "Nuget.targets" which is basically a VS project file (.csproj) containing this line
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" -nocache $(RequireConsentSwitch) -solutionDir "$(SolutionDir) "</RestoreCommand>
which takes the charge to install packages listed in packages.config file in each projects.
So if Nuget just uses the package id string, how would it know what to do if I had multiple package sources that both list available the same package Id ?
In %appdata%\nuget.config, you can see a list of "package sources" for Nuget: for a given packageId, Nuget will search for it in these package sources in the same order as in nuget.config