Created
January 18, 2020 08:30
-
-
Save chiguniiita/93cafae555029fa8c380cf6a8208d33b to your computer and use it in GitHub Desktop.
Azure Pipelines Build - Release
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .NET Desktop | |
# Build and run tests for .NET Desktop or Windows classic desktop solutions. | |
# Add steps that publish symbols, save build artifacts, and more: | |
# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net | |
trigger: | |
tags: | |
include: | |
- v* | |
pool: | |
vmImage: 'windows-latest' | |
variables: | |
solution: '**/*.sln' | |
buildPlatform: 'Any CPU' | |
buildConfiguration: 'Release' | |
steps: | |
- task: Bash@3 | |
inputs: | |
targetType: 'inline' | |
script: 'env | sort' | |
- task: NuGetToolInstaller@1 | |
- task: NuGetCommand@2 | |
inputs: | |
restoreSolution: '$(solution)' | |
- task: PowerShell@2 | |
inputs: | |
targetType: 'inline' | |
script: | | |
$CsProjPath = "$PWD\src\PhotoFolderManager\PhotoFolderManager.csproj" | |
$CsProjContent = Get-Content $CsProjPath -raw | |
$Src = @' | |
using System; | |
using System.IO; | |
using System.Text.RegularExpressions; | |
public static class ReleaseHelper | |
{ | |
public static string GetNugetVersion(string buildSourceVersion) | |
{ | |
var temp = buildSourceVersion.Substring(1).Split('.'); | |
var nugetVersion = string.Join(".", temp[0], temp[1], temp[3]); | |
return nugetVersion; | |
} | |
public static string GetVersionEmbeddedCsProj(string csproj, string build_SourceBranchName, string build_SourceVersion) | |
{ | |
var ret = csproj; | |
var patchVersion = build_SourceBranchName.Substring(1); | |
var fileVersion = patchVersion; | |
var productVersion = patchVersion + "+" + build_SourceVersion.Substring(0, 8); | |
var regPropertyGroup = Regex.Match(csproj, "<PropertyGroup>(?<PropertyGroupValue>.*)</PropertyGroup>", RegexOptions.Singleline); | |
var newPropertyGroup = regPropertyGroup.Value; | |
Func<string, string, string, string> vFunc = (string content, string tagName, string value) => | |
{ | |
var newContent = content; | |
var reg = Regex.Match(newContent, "<" + tagName + ">.*</" + tagName + ">"); | |
if (reg.Success) | |
{ | |
newContent = newContent.Replace(reg.Value, "<" + tagName + ">" + value + "</" + tagName + ">"); | |
} | |
else | |
{ | |
var pgv = regPropertyGroup.Groups["PropertyGroupValue"].Value; | |
var newpgv = pgv + " " + "<" + tagName + ">" + value + "</" + tagName + ">" + Environment.NewLine + " "; | |
newContent = newContent.Replace(pgv, newpgv); | |
} | |
return newContent; | |
}; | |
newPropertyGroup = vFunc(newPropertyGroup, "Version", productVersion); | |
newPropertyGroup = vFunc(newPropertyGroup, "FileVersion", fileVersion); | |
ret = ret.Replace(regPropertyGroup.Value, newPropertyGroup); | |
return ret; | |
} | |
} | |
'@ | |
Add-Type -TypeDefinition $Src -Language CSharp | |
$CsProjContent = [ReleaseHelper]::GetVersionEmbeddedCsProj($CsProjContent,$env:BUILD_SOURCEBRANCHNAME,$env:BUILD_SOURCEVERSION) | |
$CsProjContent | Out-File $CsProjPath | |
- task: DotNetCoreCLI@2 | |
inputs: | |
command: 'publish' | |
publishWebProjects: false | |
projects: '**/*.csproj' | |
arguments: '-c Release -o $(System.DefaultWorkingDirectory)\publish -r win-x64 --self-contained=false /p:PublishSingleFile=true' | |
zipAfterPublish: false | |
modifyOutputPath: false | |
- task: VSTest@2 | |
inputs: | |
platform: '$(buildPlatform)' | |
configuration: '$(buildConfiguration)' | |
- task: CopyFiles@2 | |
inputs: | |
SourceFolder: '$(System.DefaultWorkingDirectory)\publish' | |
Contents: '**' | |
TargetFolder: '$(Build.ArtifactStagingDirectory)' | |
- task: PublishBuildArtifacts@1 | |
inputs: | |
PathtoPublish: '$(Build.ArtifactStagingDirectory)' | |
ArtifactName: 'drop' | |
publishLocation: 'Container' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
steps: | |
- bash: | | |
env | sort | |
displayName: 'Bash Script' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
steps: | |
- task: ArchiveFiles@2 | |
displayName: 'Archive $(System.ArtifactsDirectory)\$(Release.PrimaryArtifactsOurCealias)\drop\**' | |
inputs: | |
rootFolderOrFile: '$(System.ArtifactsDirectory)\$(Release.PrimaryArtifactsOurCealias)\drop\**' | |
archiveFile: '$(System.ArtifactsDirectory)\PhotoFolderManager-$(Build.SourceBranchName).zip' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
steps: | |
- task: GitHubRelease@1 | |
displayName: 'GitHub release (create)' | |
inputs: | |
gitHubConnection: 'chiguniiita-github' | |
assets: '$(System.ArtifactsDirectory)\PhotoFolderManager-$(Build.SourceBranchName).zip' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment