请使用任何指针-如何获取在构建中使用的csproj中定义的版本?我有以下版本的yaml: 触发:- 掌握阶段:-阶段:构建"变量:buildConfiguration:'发布'职位:- 工作:水池:vmImage:'ubuntu-latest'工作区:干净:全部脚步:-任务:UseDotNet @ 2displayName:'使用.NET Core SDK'输入:packageType:sdk版本:2.2.xinstallationPath:$(Agent.ToolsDirectory)/dotnet-任务:DotNetCoreCLI @ 2displayName:"NuGet恢复"输入:命令:恢复项目:"**/*.csproj"-任务:DotNetCoreCLI @ 2displayName:生成解决方案"输入:命令:构建项目:"**/*.csproj"参数:'--configuration $(buildConfiguration)'-任务:DotNetCoreCLI @ 2displayName:测试解决方案"输入:命令:测试项目:"**/* Test/*.csproj"参数:'--configuration $(buildConfiguration)'-任务:DotNetCoreCLI @ 2displayName:'创建NuGet软件包-发行版本'输入:命令:打包packDirectory:'$(Build.ArtifactStagingDirectory)/packages/releases'参数:'--configuration $(buildConfiguration)'nobuild:正确-任务:DotNetCoreCLI @ 2displayName:'创建NuGet软件包-预发行版本'输入:命令:打包buildProperties:'VersionSuffix ="$(Build.BuildNumber)"'packDirectory:'$(Build.ArtifactStagingDirectory)/packages/prereleases'参数:'--configuration $(buildConfiguration)'-发布:"$(Build.ArtifactStagingDirectory)/packages"工件:包装"-阶段:"PublishPrereleaseNuGetPackage"displayName:'发布预发行版NuGet包'DependOn:构建"条件:成功()职位:- 工作:水池:vmImage:'ubuntu-latest'脚步:-结帐:无-下载:当前工件:包装"-任务:NuGetCommand @ 2displayName:'推入NuGet包'输入:命令:"push"packagesToPush:'$(管道.工作区)/packages/prereleases/*.nupkg'nuGetFeedType:内部"publishVstsFeed:'Unified.Mqtt.Pattern/Unified.Mqtt.Pattern-Test'-阶段:"PublishReleaseNuGetPackage"displayName:'发布发布NuGet包'DependOn:'PublishPrereleaseNuGetPackage'条件:成功()职位:-部署:水池:vmImage:'ubuntu-latest'环境:"nuget-org"战略:runOnce:部署:脚步:-任务:NuGetCommand @ 2displayName:'推入NuGet包'输入:命令:"push"packagesToPush:'$(管道.工作区)/packages/releases/*.nupkg'nuGetFeedType:外部"publishFeedCredentials:'NuGet Unified.Mqtt.Pattern' 我的 csproj 具有以下内容: < Project Sdk ="Microsoft.NET.Sdk">< PropertyGroup>< TargetFramework> netstandard2.0</TargetFramework><作者>克里斯托弗·莫利(Christopher Morley)//作者<公司>统一微系统</公司><版权/>< PackageId>统一.Mqtt.Pattern</PackageId>< Description>< Description> RangerMauve的mqtt-pattern快速库的C#端口,用于将MQTT模式与命名通配符进行匹配,以从主题中提取数据.< RepositoryUrl> https://github.com/unifiedmicrosystems/Unified.Mqtt.Pattern</RepositoryUrl>< PackageProjectUrl> https://github.com/unifiedmicrosystems/Unified.Mqtt.Pattern</PackageProjectUrl>< RepositoryType> github.com</RepositoryType>< GeneratePackageOnBuild> true</GeneratePackageOnBuild>< GenerateDocumentationFile> true</GenerateDocumentationFile>< PackageRequireLicenseAcceptance> false</PackageRequireLicenseAcceptance>< PackageIconUrl> https://www.unifiedmicro.systems/resources/unified-logo.png</PackageIconUrl>< PackageLicenseFile>许可</PackageLicenseFile></PropertyGroup>< ItemGroup><无包含=".. \ .. \ LICENSE">< Pack> True</Pack>< PackagePath></PackagePath>< VersionPrefix> 1.0.1</VersionPrefix></无></ItemGroup></Project> 解决方案 AzureDev Ops CI版本未更新版本(VersionPrefix)如果要使用 $(Build.BuildNumber)更新nuget软件包版本,则在 .NET Core pack 任务上有一个Pack选项(显示它)使用经典编辑器),则可以使用 Build.BuildNumber : 因此,我们可以在Yaml中使用此参数,例如: -任务:DotNetCoreCLI @ 2displayName:'dotnet包'输入:命令:打包packDirectory:'$(Build.ArtifactStagingDirectory)/packages/prereleases'versioningScheme:byBuildNumber 然后,我们可以获得带有以下版本的nuget软件包: 注意:我看到您的yaml文件中有两个dotnet pack任务,您应该仔细检查是否需要. 更新: 我收到以下错误,找不到版本号数据环境变量:BUILD_BUILDNUMBER.我在哪里设置?如果我不想约会,只想要1.0.1?对于 Build.BuildNumber ,我们可以在经典编辑器中将其设置为选项"标签: 对于 YAML ,您可以在yaml文件的顶部设置以下内容,以达到以下目的: 名称:1.0.$(Rev:r) 我们可以使用该变量替换硬代码 1.0 ,例如 $(Major).$(Minor).$(Rev:r) 因此,您可以检查我的YAML的参加者: 名称:$(主要).$(次要).$(版本:r)变量:专业:1次要:0水池:vmImage:'vs2017-win2016' 希望这会有所帮助.I have a Azure DevOps pipeline with a local nuget package to a local artifact repo, and then a push to nuget.org.It however is not updating the version and remains at 1.0.0-{build_ver} in the local azure DevOps project artifacts (whilst version is stuck the build_ver of the package increments as expected), but when it tries to push to nutget it fails as its the same 1.0.0 version and ignores the 1.0.1 in the project file.Any pointers please - how can i get the version defined in the csproj used in the build?I have the folowing build yaml:trigger:- masterstages:- stage: 'Build' variables: buildConfiguration: 'Release' jobs: - job: pool: vmImage: 'ubuntu-latest' workspace: clean: all steps: - task: UseDotNet@2 displayName: 'Use .NET Core sdk' inputs: packageType: sdk version: 2.2.x installationPath: $(Agent.ToolsDirectory)/dotnet - task: DotNetCoreCLI@2 displayName: "NuGet Restore" inputs: command: restore projects: '**/*.csproj' - task: DotNetCoreCLI@2 displayName: "Build Solution" inputs: command: build projects: '**/*.csproj' arguments: '--configuration $(buildConfiguration)' - task: DotNetCoreCLI@2 displayName: "Test Solution" inputs: command: test projects: '**/*Test/*.csproj' arguments: '--configuration $(buildConfiguration)' - task: DotNetCoreCLI@2 displayName: 'Create NuGet Package - Release Version' inputs: command: pack packDirectory: '$(Build.ArtifactStagingDirectory)/packages/releases' arguments: '--configuration $(buildConfiguration)' nobuild: true - task: DotNetCoreCLI@2 displayName: 'Create NuGet Package - Prerelease Version' inputs: command: pack buildProperties: 'VersionSuffix="$(Build.BuildNumber)"' packDirectory: '$(Build.ArtifactStagingDirectory)/packages/prereleases' arguments: '--configuration $(buildConfiguration)' - publish: '$(Build.ArtifactStagingDirectory)/packages' artifact: 'packages'- stage: 'PublishPrereleaseNuGetPackage' displayName: 'Publish Prerelease NuGet Package' dependsOn: 'Build' condition: succeeded() jobs: - job: pool: vmImage: 'ubuntu-latest' steps: - checkout: none - download: current artifact: 'packages' - task: NuGetCommand@2 displayName: 'Push NuGet Package' inputs: command: 'push' packagesToPush: '$(Pipeline.Workspace)/packages/prereleases/*.nupkg' nuGetFeedType: 'internal' publishVstsFeed: 'Unified.Mqtt.Pattern/Unified.Mqtt.Pattern-Test'- stage: 'PublishReleaseNuGetPackage' displayName: 'Publish Release NuGet Package' dependsOn: 'PublishPrereleaseNuGetPackage' condition: succeeded() jobs: - deployment: pool: vmImage: 'ubuntu-latest' environment: 'nuget-org' strategy: runOnce: deploy: steps: - task: NuGetCommand@2 displayName: 'Push NuGet Package' inputs: command: 'push' packagesToPush: '$(Pipeline.Workspace)/packages/releases/*.nupkg' nuGetFeedType: 'external' publishFeedCredentials: 'NuGet Unified.Mqtt.Pattern'My csproj has the following:<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> <Authors>Christopher Morley</Authors> <Company>Unified Microsystems</Company> <Copyright /> <PackageId>Unified.Mqtt.Pattern</PackageId> <Description>C# port of RangerMauve's mqtt-pattern fast library for matching MQTT patterns with named wildcards to extract data from topics.</Description> <RepositoryUrl>https://github.com/unifiedmicrosystems/Unified.Mqtt.Pattern</RepositoryUrl> <PackageProjectUrl>https://github.com/unifiedmicrosystems/Unified.Mqtt.Pattern</PackageProjectUrl> <RepositoryType>github.com</RepositoryType> <GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GenerateDocumentationFile>true</GenerateDocumentationFile> <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> <PackageIconUrl>https://www.unifiedmicro.systems/resources/unified-logo.png</PackageIconUrl> <PackageLicenseFile>LICENSE</PackageLicenseFile> </PropertyGroup> <ItemGroup> <None Include="..\..\LICENSE"> <Pack>True</Pack> <PackagePath></PackagePath> <VersionPrefix>1.0.1</VersionPrefix> </None> </ItemGroup></Project> 解决方案 Version (VersionPrefix) not being updated by AzureDev Ops CI buildIf you want to update the nuget package version with $(Build.BuildNumber), there is a Pack options on the task .NET Core pack task (Show it with classic editor), which you could use the Build.BuildNumber:So, we could use this argument in the yaml, like:- task: DotNetCoreCLI@2 displayName: 'dotnet pack' inputs: command: pack packDirectory: '$(Build.ArtifactStagingDirectory)/packages/prereleases' versioningScheme: byBuildNumberThen, we could get the nuget package with the version:Note: I saw there are two dotnet pack task in your yaml file, you should double check if it needs.Update: i get the error Could not find version number data in the following environment variable: BUILD_BUILDNUMBER. Where do i set this? What if i dont want a date, and just want 1.0.1?To the the Build.BuildNumber, we could set it Options tab in classic editor:For the YAML, you could set the following at the top of your yaml file achieves that:name: 1.0.$(Rev:r)And we could use the variable to replace the hard code 1.0, like $(Major).$(Minor).$(Rev:r)So, you could check the party of my YAML:name: $(Major).$(Minor).$(Rev:r)variables: Major: 1 Minor: 0pool: vmImage: 'vs2017-win2016'Hope this helps. 这篇关于AzureDev Ops CI版本未更新版本(VersionPrefix)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-22 13:31
查看更多