在 nuget 上禁用包类型
Disable package type on nuget
使用 dotnetcore cli 使用 packagetype 节点生成包,导致 Visual Studio 无法安装包。
在 Visual Studio 上构建包不会生成节点,但在 dotnetcore cli 上它会在 CI 中生成,如下所示:
<packageTypes>
<packageType name="api" />
</packageTypes>
CI 步数:
- 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)"
如何禁用它?
我无法在 Build Pipeline 中重现同样的问题。
对我来说,仅当我在项目文件(csproj) 中指定<PackageType>api</PackageType>
或在xx.nuspec
中定义packageTypes
元素时,才会生成PackageType
。
How can i disable it?
所以我建议你检查一下在你的project file
或者项目文件夹的xx.nuspec
文件中是否定义了关于PackageType
的定义。找到它,删除它,就不会出现这个问题。
('api'表示您或您团队中的某个人在您的团队项目中定义了 PackageType,参见 this,不同于 Dependency
和 DotnetCliTool
,api
显然是 custom PackageType)
除上述之外,您还可以尝试向 dotnet pack
任务添加参数 --no-dependencies --force --no-cache --configuration Release -p:PackageType=""
。在命令行中使用 -p:PackageType=""
可以禁用我机器中的行为。希望对您有所帮助:)
原来"PackageType"在使用DotNetCli时变得类似于保留字,将变量名称更改为"ApplicationType"以避免在nuscpec中包含包类型。
Write-Output ("##vso[task.setvariable variable=PackageType;]$packageType")
使用 dotnetcore cli 使用 packagetype 节点生成包,导致 Visual Studio 无法安装包。 在 Visual Studio 上构建包不会生成节点,但在 dotnetcore cli 上它会在 CI 中生成,如下所示:
<packageTypes>
<packageType name="api" />
</packageTypes>
CI 步数:
- 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)"
如何禁用它?
我无法在 Build Pipeline 中重现同样的问题。
对我来说,仅当我在项目文件(csproj) 中指定<PackageType>api</PackageType>
或在xx.nuspec
中定义packageTypes
元素时,才会生成PackageType
。
How can i disable it?
所以我建议你检查一下在你的project file
或者项目文件夹的xx.nuspec
文件中是否定义了关于PackageType
的定义。找到它,删除它,就不会出现这个问题。
('api'表示您或您团队中的某个人在您的团队项目中定义了 PackageType,参见 this,不同于 Dependency
和 DotnetCliTool
,api
显然是 custom PackageType)
除上述之外,您还可以尝试向 dotnet pack
任务添加参数 --no-dependencies --force --no-cache --configuration Release -p:PackageType=""
。在命令行中使用 -p:PackageType=""
可以禁用我机器中的行为。希望对您有所帮助:)
原来"PackageType"在使用DotNetCli时变得类似于保留字,将变量名称更改为"ApplicationType"以避免在nuscpec中包含包类型。
Write-Output ("##vso[task.setvariable variable=PackageType;]$packageType")