简体   繁体   中英

Creating NuGet using Team Foundation Server missing dependencies

I have created a simple class library in .net standard 2.0 with a few nuget dependencies like Dapper.

I am using Team Foundation Server 16 to then build and package the project. My issue is, that when I then browse to my new NuGet package, it does not list it's dependencies in the NuGet package manager in VS and I have to install them manually afterwards.

Creating a nuget package of the same class library from Visual Studio 2019 locally works as intended.

My build tasks on TFS are:

  1. Use nuget 5.4.0
  2. NuGet restore
  3. Build solution
  4. Run script (A .bat file for updating version number)
  5. NuGet pack
  6. Publish build artifact

The NuGet pack uses default settings with command "pack" and path pointing only to .csproj file.

Creating a nuget package of the same class library from Visual Studio 2019 locally works as intended.

It's one issue about nuget pack command. When you pack the .net standard project in VS locally, it(right-click=> pack button) actually calls dotnet cli instead of nuget.exe to do the pack job.

For now, nuget pack command can't work well with those projects that use PackageReference to manage nuget packages. (Including .net framework projects with PackageReference , .net core and .net standard projects).

More details see discussions here and here .

To resolve that issue(For TFS2017 and above):

Use dotnet pack command instead of nuget pack command. And for pipeline in tfs, use dotnet restore, build, pack tasks instead of nuget restore, nuget pack tasks.

在此处输入图片说明

Update1 for TFS2016:

Since TFS will run those tasks in tfs agents, one alternative way is to install .net core sdk manually, and then use command-line task to execute dotnet pack command to create nuget packages.

.net core sdk download link here .

Update2:

Also, we can still use nuget pack command/task. To include those dependencies, we need to create an extra xx.nuspec file with content similar to this:

<?xml version="1.0" encoding="utf-8"?>
<package >
  <metadata>
    <id>PackageName</id>
    <version>1.0.0</version>
    <title>xxx</title>
    <authors>xxx</authors>
    <owners>xxx</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <license type="expression">MIT</license>
    <description>xxx</description>
    <releaseNotes>xxx</releaseNotes>
    <copyright>Copyright 2020</copyright>
    <tags>Tag1 Tag2</tags>
    <dependencies>
        <dependency id="Dapper" version="1.30.0"/>
        //define other dependencies manually here. 
   </dependencies>
  </metadata>
</package>

Place this file in same directory where xx.csproj exists, and then nuget pack command/task can now create the package with dependencies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM