0
votes

I am using Visual Studio Team Services to run builds for a library that I publish as a Nuget package.

The project contains a nuspec file which specifies the name, description, project url and other static info.

This nuspec file is referenced on the Nuget pack build action in VSTS

enter image description here

I would like to include the info about dependencies as well, however, I do not want to manage that manually in the nuspec XML (error prone and time consuming).

The nuspec file does not contain the element, so I hoped VSTS NuGet pack action would include them automatically.

Is there any way to achieve that?

2

2 Answers

0
votes

You can use the new "SDK style" csproj format to move NuGet concerns into a single csproj file that lets you specify dependencies and static metadata in one place.

Best to start out creating a .NET Standard Library and change the <TargetFramework> property from netstandard2.0 to the framework you targeted before - e.g. net452. (Or select an appropriate .NET Standard version)

This project type can be packed using msbuild /t:Pack or dotnet pack

When you add project or NuGet package references, these will automatically turn into dependencies during packing and if you reference packages via wildcard (1.2.*), the package will depend on the version resolved during restore. VS offers a dialog to edit package metadata for this project type in the project properties.

0
votes

Apparently, quite a simple solution exists.
You can set your VSTS Nuget pack task to use the csproj file (not the nuspec), however it will still access the nuscpec to get the metadata. See the logs below:

enter image description here

To reiterate, instead of setting the pattern for the nuspec file in the build task in VSTS, set the path to the csproj file.