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.
Related
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.
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
I have Directory Structure like -
Projects
.nuget
NuGet.exe
NuGet.config
NuGet.targets
**packages (I want to download package for different solution HERE ONLY)**
Sources
Applications
App1
App1.sln (Solution File)
**packages (NuGet downloads packages here first then copies to expected folder, WHY??)**
App1 (Porject Directory)
App1.csproj
App2
App2.sln (Solution File)
**packages (NuGet downloads packages here first then copies to expected folder, WHY??)**
App2 (Porject Directory)
App2.csproj
I have referenced .nuget folder in each solution using following code
Project("{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}") = ".nuget", ".nuget", "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx}"
ProjectSection(SolutionItems) = preProject
..\..\..\.nuget\NuGet.Config = ..\..\..\.nuget\NuGet.Config
..\..\..\.nuget\NuGet.exe = ..\..\..\.nuget\NuGet.exe
..\..\..\.nuget\NuGet.targets = ..\..\..\.nuget\NuGet.targets
EndProjectSection
EndProject
In every project file (.csproj), I have referenced common NuGet.targets using,
<Import Project="..\..\..\..\.nuget\NuGet.targets" Condition="Exists('..\..\..\..\.nuget\NuGet.targets')" />
In NuGet.config, I have added following line so that it should (must) copy packages in EXPECTED folder ONLY
<add key="repositoryPath" value="..\packages" />
I have mapped Projects folder with TFS and it asks me to add files on both locations because of above problem
NuGet will look for the NuGet.config file based on the current solution's directory.
So taking your App1 solution if the Projects directory is in c:\Projects then your App1.sln file will be in the c:\Projects\Sources\Applications\App1 directory. Now NuGet will look for the NuGet.config directory in:
c:\Projects\Sources\Applications\App1\.nuget\NuGet.Config
c:\Projects\Sources\Applications\App1\NuGet.Config
c:\Projects\Sources\Applications\NuGet.Config
c:\Projects\Sources\NuGet.Config
c:\Projects\NuGet.Config
c:\NuGet.Config
After this it then looks in machine wide locations but I will ignore these for now.
Looking at your directory structure the Projects.nuget directory will not be checked by NuGet. It is not a parent of any of the solution directories.
I would look at putting a NuGet.Config file with the repositoryPath setting in the Sources directory or the Projects directory (not in the .nuget directory). Or having two NuGet.Config files, one in the App1.nuget directory and one in the App2.nuget directory.
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
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.