我有一个Azure构建管道,我想用它来制作一个NuGet包。
.csproj有
VersionPrefix>1.2.0</VersionPrefix>我希望NuGet的版本:
master,则附加分支名称(从而生成一个预发布包)。因此包版本可以是:1.2.0.8、1.2.1-hotfix20210525、1.2.1、.在枕骨yml中我有:
${{ if eq(variables['Build.SourceBranchName'], 'master') }}:
buildConfiguration: 'Release'
tag: ''
${{ if ne(variables['Build.SourceBranchName'], 'master') }}:
buildConfiguration: 'Debug'
tag: ${{ format('-{0}', variables['Build.SourceBranchName']) }}
...
- task: DotNetCoreCLI@2
displayName: 'dotnet pack Filename'
inputs:
command: 'pack'
packagesToPack: 'Folder/Filename.csproj'
includesymbols: true
includesource: true
nobuild: true
buildProperties: 'VersionSuffix="$(Build.BuildId)$(tag)"'
versionSuffix: '$(Build.BuildId)$(tag)'
outputDir: '$(Build.ArtifactStagingDirectory)'
arguments: '--version-suffix $(Build.BuildId)$(tag)'但这不起作用,因为versionb后缀意味着在连字符之后出现的副词,因此我的所有包似乎都是预发布的。
这能工作吗?--使用版本号作为版本号的一部分,并且只使用tag作为预发布的名称?
**编辑:将所需的值赋值给变量**
我尝试制作所需的版本号,并将其完全指定为pack命令。但当然不管用了。
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$xml = [Xml] (Get-Content Folder\Filename.csproj)
$versionPrefix = $xml.Project.PropertyGroup.VersionPrefix
echo $versionPrefix
$version = $($versionPrefix).$(Build.BuildId)$(tag)
echo "ECHO"
echo $version
echo $(version)========================== Starting Command Output ===========================
##[debug]Entering Invoke-VstsTool.
##[debug] Arguments: '-NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'C:\agent\_work\_temp\fa4b86cc-c5a4-41f8-b6b8-a90492732482.ps1'"'
##[debug] FileName: 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe'
##[debug] WorkingDirectory: 'C:\agent\_work\12\s'
##[command]"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'C:\agent\_work\_temp\fa4b86cc-c5a4-41f8-b6b8-a90492732482.ps1'"
At C:\agent\_work\_temp\fa4b86cc-c5a4-41f8-b6b8-a90492732482.ps1:5 char:35
+ $version = $($versionPrefix).10504-pipeline
+ ~~~~~~~~~
Unexpected token '-pipeline' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
##[debug]Exit code: 1
##[debug]Leaving Invoke-VstsTool.
##[error]PowerShell exited with code '1'.发布于 2021-05-25 12:17:29
恐怕通过version-prefix设置是不可能的,您需要提供完整的包装
- task: DotNetCoreCLI@2
displayName: "dotnet pack"
inputs:
command: custom
custom: pack
arguments: >
Folder/Filename.csproj
--no-build
-p:PackageId=myId
--output $(Build.ArtifactStagingDirectory)
-p:PackageVersion=2.1.0$(tag)
-p:Configuration=$(buildConfiguration)
packagesToPack: '**/*.csproj'
versioningScheme: 'off'
outputDir: '$(Build.ArtifactStagingDirectory)'但是,在本例中,您需要首先从csproj获取VersionPrefix的currect值。
https://stackoverflow.com/questions/67686319
复制相似问题