Disable package type on nuget

586 views Asked by At

Using dotnetcore cli the packages are being generated with a packagetype node, causing Visual Studio to not be able to install the package. Building the package on Visual Studio does not generate the node, but on dotnetcore cli it gets generated in CI like this:

 <packageTypes>
      <packageType name="api" />
    </packageTypes>

CI steps:

- task: DotNetCoreCLI@2
  displayName: "${{ parameters.name }} - Restore"
  inputs:
    command: 'restore'
    projects: '${{ parameters.projects }}'
    feedsToUse: 'config'
    nugetConfigPath: '$(Build.SourcesDirectory)/NuGet.Config'

- task: DotNetCoreCLI@2
  displayName: "${{ parameters.name }} - Build"
  inputs:
    command: 'build'
    projects: '${{ parameters.projects }}'
    arguments: "--configuration Release --no-cache"

- task: DotNetCoreCLI@2
  displayName: "${{ parameters.name }} - Pack" 
  inputs:
    command: 'pack'
    nobuild: true
    packagesToPack: $(ProjectsToPack)
    versioningScheme: 'byEnvVar'
    versionEnvVar: 'NugetVersion'
    arguments: '--no-dependencies --force --no-cache'

- task: DotNetCoreCLI@2
  displayName: "${{ parameters.name }} - Push"
  inputs:
    command: custom
    custom: nuget
    arguments: >
      push "$(Build.ArtifactStagingDirectory)\*.nupkg"
      -s "$(NugetFeed)"
      -k "$(NugetToken)"

How can i disable it?

2

There are 2 answers

1
BrunoMartinsPro On BEST ANSWER

It turns out "PackageType" became similar to a reserved word when using DotNetCli, changed the variable name to "ApplicationType" to avoid having the package type in the nuscpec.

  Write-Output ("##vso[task.setvariable variable=PackageType;]$packageType")
0
LoLance On

I can't reproduce same issue in Build Pipeline.

For me, the PackageType will be generated only when I specify the <PackageType>api</PackageType> in project file(csproj) or I define the packageTypes elements in xx.nuspec.

How can i disable it?

So I suggest you check if there's any definition about PackageType defined in your project file or in the xx.nuspec file in project folder. Find it, delete it and this issue won't occur.

(The 'api' indicates you or someone in your team define the PackageType in your team project, see this, different from Dependency and DotnetCliTool, api is apparently a custom PackageType)

Apart from above, you can also try adding arguments --no-dependencies --force --no-cache --configuration Release -p:PackageType="" to your dotnet pack task. Using -p:PackageType="" in command-line can disable the behavior in my machine. Hope it helps :)