示例项目:https://dev.azure.com/guorj/_git/PackDemo
因为一些需求,在代码有改动以后需要更新响应的package,以供其他项目来使用,但是每次手动打包比较麻烦,就想着给自动化了,可怜自动化出来这么久都没有用过。
代码托管在微软的Azure上,所以使用的是Azure Pipelines功能。
懒得细写了,包含了.net framework 和 .net core的自动编译打包功能,监听了csrpoj文件或者assembly.cs文件,因为不想每次提交都会发版本,只有这两个文件有改动才触发pipeline,最主要的想打包时要修改版本号。
该行语句指的是Self Host的Agent Pool,也可以使用微软提供的,个人账户默认每个月有1800分钟的编译时间。
pool:
name: "vsts-agent-guorj-pc"
编译 .net framework 的 pipeline 脚本
https://dev.azure.com/guorj/_git/PackDemo?path=/Azure-Pipelines/azure-pipelines-DotNetLib.yml
trigger:
branches:
include:
- main
paths:
include:
- DotNetLib/Properties/AssemblyInfo.cs #DotNetLib/**
- Azure-Pipelines/azure-pipelines-DotNetLib.yml
pool:
name: "vsts-agent-guorj-pc"
variables:
solutionPath: 'CommonLib.sln'
projectPath: 'DotNetLib/DotNetLib.csproj'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
displayName: 'Use NuGet >=6.12.x'
inputs:
versionSpec: '>=6.12.x'
- task: NuGetCommand@2
displayName: 'nuget restore'
inputs:
command: 'restore'
feedsToUse: 'select'
#vstsFeed: 'PackDemo/PackDemoFeed'
#includeNuGetOrg: false
restoreSolution: $(projectPath)
displayName: 'Restore NuGet Packages'
- task: NuGetCommand@2
displayName: 'nuget pack'
inputs:
command: 'custom'
arguments: 'pack -Build -Properties Configuration=$(buildConfiguration) -OutputDirectory $(Build.ArtifactStagingDirectory) $(projectPath)'
- task: NuGetCommand@2
displayName: 'nuget push'
inputs:
command: 'push'
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: 'PackDemo/PackDemoFeed'
versioningScheme: 'off'
allowPackageConflicts: true # Allow duplicates to be skipped
编译 .net core 项目的 pipeline 脚本
https://dev.azure.com/guorj/_git/PackDemo?path=/Azure-Pipelines/azure-pipelines-CommonLib.yml
trigger:
branches:
include:
- main
paths:
include:
- CommonLib/CommonLib.csproj # CommonLib/**
# # the build will run on a Microsoft hosted agent, using the lastest Windows VM Image
pool:
name: "vsts-agent-guorj-pc"
# vmImage: 'vsts-agent-guorj-pc'
# these variables are available throughout the build file
# just the build configuration is defined, in this case we are building Release packages
variables:
buildConfiguration: 'Release'
#The build has 3 seperate tasks run under 1 step
steps:
- task: DotNetCoreCLI@2
inputs:
command: 'restore'
arguments: '--configuration $(buildConfiguration)'
projects: 'CommonLib/CommonLib.csproj'
# The first task is the dotnet command build, pointing to our csproj file
- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
command: 'build'
arguments: '--configuration $(buildConfiguration)'
projects: 'CommonLib/CommonLib.csproj'
# The second task is dotnet pack command again pointing to the csproj file
# The nobuild means the project will not be compiled before running pack, because its already built in above step
- task: DotNetCoreCLI@2
displayName: "dotnet pack"
inputs:
command: 'pack'
arguments: '--configuration $(buildConfiguration)'
packagesToPack: 'CommonLib/CommonLib.csproj'
nobuild: true
versioningScheme: 'off' # Required when command = pack. Allowed values: off, byPrereleaseNumber (Use the date and time), byEnvVar (Use an environment variable), byBuildNumber (Use the build number). Default value: off.
- task: NuGetCommand@2
inputs:
command: 'push'
packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: 'PackDemo/PackDemoFeed'
标签:inputs,task,Pipelines,artifacts,CommonLib,guorj,command,build,Net
From: https://www.cnblogs.com/grj1046/p/18591081