No Dependencies are automatically installed when adding nuget package - tfs

I'm creating a small nuget package for internal using (I created .NET standard project to use both .NET Framework or .NET Core). I created a Build Definition to build the library then push it to the Nuget Feeds of my company.
I have 2 questions:
How can I set it automatically increase the version of the my nuget package when Queue the build in tfs 2017 & Can I set some information like Author, Company...for my package?
After having the Package in the TFS Packages. I tried to add my nuget package to my project. The nuget referenced package were not automatically added to the project. I can see, it displayed "No dependencies" but in fact, I used 2 packages in my library are Newtonsoft & StackExchange.Redis. So when I run the debug, error shown "Could not find the StackExchange.Redis..."
That's strange
In my Libary project setting, I can see

There are two ways to package nuget packages. You can use "nuget pack" or "dotnet pack" (if you have some dotnet core in your solution). The difference is that dotnet pack will create a dependency section in your nuspec and you would see dependency upon installing where nuget pack will not by default unless you use an actual nuspec file. If you do create a nuspec file, you'll need to add the dependency section to you file in order to have them pop up at installation. Check here for info on the nuspec file.
For you version number it's also actually in the nuspec file in the metadata section there is a tag with the version you want. The TFS nuget pack task as a drop down you can use to send in a version number. For this task you can either use a nuspec file or the csproj directly.
You have the same options for dotnet pack using the dotnet core task
Update:
If you change your build number version pattern in the options tab for a 4 (or 3) digit pattern like $(Date:yyyy.MM.dd).$(Rev:r) e.g. 2020.03.05.xx (where xx will increment for each build in the same day and go down to 1 the next day) or 1.0.$(Rev:r) which will be 1.0.xx that will increment forever until you change the 1.0 value and then use the "Use Build Number" it will do it for you.

Related

Nuget Restore in MS Build Step

In my asp.net web application, i have solution with 5 projects and nuget.org. In TFS Build Definition,
1) While building the whole solution in Visual Studio Build Task
Nuget packages getting restored.
2) While trying to generate executable files for individual projects in MS Build Task
If I select Restore Nuget packages, It's not finding nuget packages and step getting failed with message - "Process 'NuGet.exe' exited with code '1'."
I have tried many references online and none worked. Any suggestions on how to solve this?
Do i need to make any changes in the nuget.config file to support restoring
packages to individual projects.
Do not directly select Restore Nuget pacakges in MS build task configuration. This option is deprecated. To restore NuGet packages, add a NuGet Installer step before the build.
(Important) This option is deprecated. Make sure to clear this
checkbox and instead use the NuGet Installer build step.
Source Link: MSBuild
Besides, you could also build single project not the entire solution in Visual Studio Build task. Just select the project (.*proj) files instead of .sln file.
Unless you are building a customized MSBuild project file, then we recommend you use the MSBuild step instead of the Visual Studio Build step.
You could also try to build single project using Visual Studio Build task, see if the issue is still exists.
Same problem, downgraded to 4.4.1. it helped

How to set TFS NuGet restore to take all the needed version from sln file?

I'm using the TFS step to restore my NuGet packages.
In the "Path to solution or packages.config" field I'm setting the path to the sln file.
The problem that I'm getting is that in my solution I have 2 projects:
Project "A" referencing "commom.package" version 1.1 and
project "B" referencing "commom.package" version 1.3
After the restore step I'm only getting the 1.3 version in the package directory, and after project "A" got compiled I can see in the "bin\release" folder that It's having the 1.3 version instead of the 1.1.
How can I solve this issue? Do I need to set restore for every project in the solution - meaning every package.config file?
The nuget restore task is just using nuget.exe command to restore the packages. If you use the nuget.exe command in local, will also get the same result. Package.conifg is project level, not solution level. So if you directly restore the solution in this case, it will only get one version 1.3 which apply to both projects.
However in VS , there is an option Automatically check for missing packages during build in Visual Studio. You will get both version 1.1 and 1.3 in VS restore.
To resolve this issue you have to set restore for every package.config file. Unlike restore the whole solution, you also need to use -PackagesDirectory in NuGet Arguments of the task.

Project to Project Reference does not generate right nuget dependency when using GeneratePackageOnBuild

I have 3 projects in my solution.
As part of the build process in TFS I generate 3 NuGet pacakges by using the GeneratePackageOnBuild property in my project file (new csproj for VS 2017).
Project1
Project2
Project3
|_ ProjectReference Project1.csproj
|_ ProjectReference Project2.csproj
I have 2 different builds. One for preview and another one for final builds.
When using the one for preview I add -preview-<BuildId> to all projects.
The generated NuGet packages are successfully generated with this version. But the package dependencies are generated without the preview suffix.
How can I tell MSBuild to generate the dependencies with the right version?
UPDATE:
It seems like the nuspec files that are generated at build time are created based on project.assets.json I have conditional properties in project imports for versioning and it seems that when project.assets.json is generated the variables for conditions don't exist for referenced projects and generating the wrong dependency version which then flows into the automatically generated nuspec file for the package.

VisualStudio 2013 list all NuGet packages

I have a mvc 5 web project with a number of NuGet packages installed (like email, log, pagedlist etc).
In a new similar project I would like to install the same NuGet packages. How can I in the old project list all installed NuGet packages?
You can find a packages.config file in the old project's root directory.
You can copy it to the new project.
If you go to Tools -> NuGet Packet Manager -> Packet manager settings and check Allow NuGet to download missing packages and the other check box that states Automatically check for missing packages during build in Visual Studio it will download it for you next time you build.
If you want to list all installed nuget packages for the project take a look at this one.
http://blogs.msdn.com/b/david_kidder/archive/2014/08/19/micro-blog-how-to-list-installed-nuget-packages-from-package-manager-console-and-be-able-to-read-them.aspx
You might also want to enable nuget package restore to restore the packages when rebuilding your project/s.
Here's another link for you - http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html
In the root folder of your original project find a packages.config file. Copy its contents to your new project, same file name.
Go to Visual Studio > Tools > Package Manager Settings > General
Enable "Allow Nuget to download..." and "Automatically check for missing..."
Now build your new project
Most of the answers here are partially correct.
The first part is true. The packages.config file lists all packages that are used by the project.
However, all the answers about using Package Restore are incorrect. Package Restore will download any missing packages, however it is NOT the same as installing a package into a project. It will not add references, run any install.ps1 scripts, or add files, modify .config, etc. Package Restore simply downloads missing packages. It is assumed that the packages were already installed to the project.
In order for the packages to be correctly installed in your new project, open the Package Manager console, then type:
Update-Package -ProjectName MyProjectName -Reinstall
This will force NuGet to run through the install process and correctly install the package into your project.

Referenced Dll's not found in Team Foundation Service (or: nuget packages not available on other pc)

when I create a build for the Team Foundation Service, I get all kind of reference dll's not found exceptions.
These references are added by nugget packages.
I've added the 'package restore' option on the solution which added 3 files in a .NuGet folder.
EDIT
When i got the solution from TFS on another pc, i got the same errors (missing dll's), so it's not only the TFS build service having problems.
The missing dll's are are missing files from installed nuget packages (some are part of the default VS template, Unity was a package i added later), which (the packages) are added on the first pc, but then are missing on the next pc (that's why i added the 'or' in the title of this question)
How can i get the Nuget added files on pc2 too?
I guess you've found a solution by now. I write this just to provide an answer for this question.
To have NuGet packages automatically downloaded on another PC, you need to enable NuGet package restore on build. You do this in two steps:
Right click the solution and select Enable NuGet Package Restore.
This will add a .nuget solution folder with NuGet.Config, NuGet.exe and NuGet.targets underneath it. These files should actually be checked in to source control, but the binary file is tiny. It will also modify the MSBuild scripts in all projects of the solution to import the NuGet.targets file to hook NuGet into the build process.
In Tools -> Library Package Manager -> Package Manager Settings make sure the option 'Allow NuGet to download missing packages during build' is checked.
This step must be done on all machines.
Now the BuildDependsOn property of all project build scripts should make the RestorePackages target in NuGet.targets kick in and download missing packages before you get build errors for missing references.

Resources