Nuget Packager task - dependency is not added - visual-studio

I'm using Visual Studio Team Services to automate the creation of a nuget package. This package has a dependency on another nuget package (Newtonsoft.Json v8.0.3). I have configured a Nuget Packager task as part of the build:
But the generated package doesn't contain the reference to the nuget package:
Running the following script on my local machine to generate the package:
nuget pack myproject.csproj -Symbols -IncludeReferencedProjects -Properties Configuration=Release -OutputDirectory bin/Release
I can see that the dependency is added to the generated package:
What am I missing here? Why the dependencies are not being added to to package that is being generated on the build server?

"IncludeReferencedProjects" is used to add the referenced project to the nuget package, not the referenced nuget packages.
Include referenced projects either as dependencies or as part of the
package. If a referenced project has a corresponding nuspec file that
has the same name as the project, then that referenced project is
added as a dependency. Otherwise, the referenced project is added as
part of the package. Learn more at NuGet.org.
When you create the nuget package for the project which referenced to another nuget package. The nuget package dependency will be added automatically if the nupkg file exists in the packages folder. For your issue, you can add a "NuGet Installer" task in your build definition to restore the nuget package files for your solution. And then when you create the nuget package for your project, the referenced nuget package will be added as dependency.

I have found a solution for my problem, even though I don't understand why the package was not being created properly.
So basically I have 2 builds:
a "generic" build that will compile the entire solution and run unit tests, etc (automatic, triggered on commit)
a build to generate the nuget package (manual)
This problem is on the 2nd build. I was trying to understand what were the differences between creating the package manually on my local machine and creating the package on the build server and I realized that on the build server I was not getting the source code for the solution, only for the project folder and the .nuget folder. Given that I have more than 40 projects in the solution it makes no sense to get the whole source code for the 2nd build, right? But for some reason this is not enough to generate the nuget package properly.
So, the solution to my problem was to get the source code for the following files/folders:
Project folder
.nuget folder (needed when restoring/installing the missing packages)
Solution file (mysolution.sln)

Related

How do you test a nuget package?

I am producing a nuget package (some c# dlls that are then built into a nuget package and then uploaded to our nuget server)
I would like to have a way to test the package before I bother uploading it to a server.
I have a test project that has the package installed
Is there a way (in command line etc) to uninstall the release package from the project, and install a candidate package from the local machine in its place? (to test that the new package build is actually good?).
It would be good to have a one click update and restore of this candidate package too, so if I do a code change in my code thats being packaged, I can just have a one-click "build -> package candidate package -> restore candidate package on the test project".
In short: I change code in my package. click a button, then just hit F5 in the test project and it runs with the latest code changes.
AFAK, to realize this, you have to modify the PackageVersion node to make such nuget package unique every time.
Assume that your lib project and main project are all new-sdk projects.
1) Add such node under the csproj of the class library project and make the PackageVersion unique. Also check this link:
<PropertyGroup>
<PackageVersion>1.0.0-re-$([System.DateTime]::Now.ToString('yyyyMMddHHmm'))</PackageVersion>
</PropertyGroup>
2) change your main project's csproj file to this:
<ItemGroup>
<PackageReference Include="Lib" Version="1.0.0-*" />
</ItemGroup>
It will use the latest version of the nuget under the nuget package source.
3) if you modify the lib project and then finish it, please right-click on the lib project Properties-->Pack to generate the new version.
4) then build the main project first, and then you can use the latest changed nuget package's code on the main project.
And if you want to restore to use the previous version of the nuget package, there is no way but you only have to install that version manually under Nuget Package Management.

Nuget package did not install on target machine

I've created a windows service that uses Microsoft Visual Studio Installer Projects to install the service. The service was running fine until it needed the references from the Nuget package Microsoft.SqlServer.SqlManagementObjects
How do I add this package to the setup project so the references are available or can I simply install the nuget package on the target machine?
How do I add this package to the setup project so the references are available or can I simply install the nuget package on the target machine?
Since nuget does not support the setup project, so we could not add that nuget package to the setup project directly.
To resolve this issue, the most direct method is manually add the .dll files in nuget package to the setup project (Right click the setup project->Add->Assemble...->Browse).
If manually adding the .dll file is not what you want, you can add a blank library project to the setup solution, then add the that nuget package to the library project.
Add the Project Output of the library project to the setup project (Add->Project Output...->Primary output):
In this case, all the .dll files in the nuget package are available for your setup project.
Hope this helps.

NuGet package without assemblies complains about lack of assemblies

I'm creating a content-only NuGet package (e.g. no DLLs, just text files in this case). When I install the package, I get this error message:
Install-Package : Could not install package 'CodeGenerator.Templates.EF6-CQRS-Aurelia 1.0.2'. 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. For more information, contact the package author.
This is all true, but I don't want to target any framework for this package -- how can I accomplish this?
The package is here: https://www.nuget.org/packages/CodeGenerator.Templates.EF6-CQRS-Aurelia
I had the same problem but with only a build target (and no assemblies).
Just adding an empty lib folder to my root package directory fixed it.
(Maybe a bug in NuGet. I have submitted an issue.)

Should NuGet Spec detect dependencies?

I've just run nuget spec in the folder where my .csproj file is and it didn't write the dependencies to the .nuspec file. Should it have?
The solution has package restore enabled and builds fine on TeamCity.
Running nuget spec does not automatically include dependencies to other NuGet packages in your project. However, running nuget pack MyProject.csproj when you also have a nuspec-file will result in a nupkg-file where NuGet packages used in MyProject are included as dependencies in your package.
It is also worth noting that as of v2.5 (which is planned to be released some time at the end of April I believe), you'll also have the option to additionally include dependencies to other projects in your solution that also have nuspec-files:
When building a package from a project, when
-IncludeReferencedProjects is specified, projects referenced by the project are either added as a dependency of the package, if nuspec
file exists, or are added into the package if nuspec file doesn't
exist.
See changelog.txt for v2.5 for details.

How do I create a NuGet package from a project file so it includes the necessary assemblies?

To generate a NuGet package I'm currently using the command:
nuget pack project.csproj -Prop Configuration=Release
which I expected would package up the files in the bin\Release folder, i.e. the result of building the project. This folder has several MB of assemblies, however the nupkg file that gets created is only 7kb, which doesn't seem to include any of these files.
I'm running the nuget command from TeamCity so I'm trying to avoid manually editing a nuspec file.
What is the best way to package a project like this using NuGet?
TeamCity 7.0 is finally here and it has its own NuGet server built in.
You can simply ask it to take care of your packages whether you want to publish it locally or/and to nuget.org
TeamCity and NuGet

Resources