0

I can create a proper nuget package for my .net standard 2.0 library by right clicking the project in VS2019 and selecting pack.

The .nuspec contains

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>SBD.Standard</id>
    <version>1.0.0</version>
    <authors>SBD.Standard</authors>
    <owners>SBD.Standard</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package Description</description>
    <dependencies>
      <group targetFramework=".NETStandard2.0">
        <dependency id="Microsoft.Data.SqlClient" version="1.1.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.EntityFrameworkCore" version="3.1.1" exclude="Build,Analyzers" />
        <dependency id="Microsoft.EntityFrameworkCore.SqlServer" version="3.1.1" exclude="Build,Analyzers" />
        <dependency id="Newtonsoft.Json.Schema" version="2.0.7" exclude="Build,Analyzers" />
        <dependency id="RestSharp" version="106.10.0" exclude="Build,Analyzers" />
        <dependency id="System.Data.SqlClient" version="4.6.1" exclude="Build,Analyzers" />
      </group>
    </dependencies>
  </metadata>
</package>

However if I create the nuget in Azure Devops using the following command in azure-pipelines.yml

- task: DotNetCoreCLI@2
  inputs:
    command: 'pack'
    packagesToPack: '**/SBDSTD.*.csproj'

Then I look at the .nuspec file for the package created it contains

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
  <metadata>
    <id>SBD.Standard</id>
    <version>2.0.0-CI-20200212-174043</version>
    <title>SBD.Standard</title>
    <authors>SBD.Standard</authors>
    <owners>SBD.Standard</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Description</description>
    <dependencies />
  </metadata>
</package>

How do I get Devops to create the correct .nuspec file?

Kirsten
  • 15,730
  • 41
  • 179
  • 318
  • https://stackoverflow.com/questions/60178092/could-not-load-file-or-assembly-microsoft-data-sqlclient – Kirsten Feb 12 '20 at 22:03
  • What is version of the .net core you are using? I use the .net core 3.1.101 test it in my local and devops, the .nuspec file in the package is correct, including the dependencies. – Leo Liu Feb 13 '20 at 06:19
  • I didnt think I was using .net core. The target framework is .netstandard 2.0 – Kirsten Feb 13 '20 at 06:40
  • 1
    but as you said, you use the dotnet core task to pack the package, it will use the .net core. – Leo Liu Feb 13 '20 at 06:44
  • I am using the free hosted agent in Azure Devops. How do I find out the .net core version? – Kirsten Feb 13 '20 at 06:47
  • you just need share the hosted agent name to me, I will check it, if possible, would you mind share your pack task log or a sample in your question? So that I could check the reason for this issue, since I could not reproduce this issue on my side. – Leo Liu Feb 13 '20 at 06:53
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/207732/discussion-between-kirsten-greed-and-leo-liu-msft). – Kirsten Feb 13 '20 at 07:03

1 Answers1

1

How do I get Azure DevOps to create a correct nuspec for a .net standard 2.0 project?

After a long troubleshooting with Kirsten Greed, we figured it out.

We resolve this following YAML to regenerate the nuget package for a .net standard 2.0 project:

trigger: none
pool:
  vmImage: vs2017-win2016

steps:
- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: restore
    projects: xxxx/xxx.csproj
    vstsFeed: 'XXXXXXX'

- task: DotNetCoreCLI@2
  displayName: 'dotnet build'
  inputs:
    projects: xxx/xxx.csproj
    arguments: '/p:Configuration=Release'

- task: DotNetCoreCLI@2
  displayName: 'dotnet pack'
  inputs:
    command: pack
    packagesToPack: xxx/xxx.csproj

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'

Then we could check the .nuspec file after unzipping the generated package.

In addition, we could use nuget push task to publish the generated package to our feed, like:

- task: DotNetCoreCLI@2
displayName: 'dotnet push'
inputs:
command: push
publishVstsFeed: 'XXXX'

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • I also just noticed in my project file something that can't have helped! false – Kirsten Feb 13 '20 at 09:38
  • The property is used to disable generate the nuget package when you build the project. If you have any other question, open a new thread with detailed info. – Leo Liu Feb 13 '20 at 09:41