|
| 1 | +function WriteXml([System.Xml.XmlDocument]$xml, [string]$file) |
| 2 | +{ |
| 3 | + $encoding = New-Object System.Text.UTF8Encoding($true) |
| 4 | + $writer = New-Object System.IO.StreamWriter($file, $false, $encoding) |
| 5 | + $xml.Save($writer) |
| 6 | + $writer.Close() |
| 7 | +} |
| 8 | + |
| 9 | +function GetVersion() |
| 10 | +{ |
| 11 | + $file = "$($rootPath)\build\version.props" |
| 12 | + $xml = New-Object -TypeName XML |
| 13 | + $xml.Load($file) |
| 14 | + $version = $xml.Project.PropertyGroup.Version |
| 15 | + if($version.contains("VersionSuffixVersion")) |
| 16 | + { |
| 17 | + $version = "{0}.{1}{2}{3}" -f $xml.Project.PropertyGroup.VersionMain,$xml.Project.PropertyGroup.VersionPrefix,$xml.Project.PropertyGroup.VersionSuffix,$xml.Project.PropertyGroup.VersionSuffixVersion |
| 18 | + } |
| 19 | + else |
| 20 | + { |
| 21 | + $version = "{0}.{1}" -f $xml.Project.PropertyGroup.VersionMain,$xml.Project.PropertyGroup.VersionPrefix |
| 22 | + } |
| 23 | + return $version |
| 24 | +} |
| 25 | + |
| 26 | +function SetOsharpNSVersion() |
| 27 | +{ |
| 28 | + $file = "$($rootPath)\build\OSharpNS.nuspec" |
| 29 | + Write-Host ("正在更新文件 $($file) 的版本号:$($version)") |
| 30 | + $xml = New-Object -TypeName XML |
| 31 | + $xml.Load($file) |
| 32 | + $xml.package.metadata.version = $version |
| 33 | + $nodes = $xml.package.metadata.dependencies.group.dependency |
| 34 | + foreach($node in $nodes) |
| 35 | + { |
| 36 | + $node.version = $version |
| 37 | + } |
| 38 | + WriteXml $xml $file |
| 39 | + Write-Host "OSharpNS.nuspec 版本号更新成功" |
| 40 | +} |
| 41 | + |
| 42 | +function BuildNugetPackages() |
| 43 | +{ |
| 44 | + $output = "$($rootPath)\build\output" |
| 45 | + if(Test-Path $output) |
| 46 | + { |
| 47 | + Remove-Item ("$($output)\*.*") |
| 48 | + Write-Host ("清空文件夹:$($output)") |
| 49 | + } |
| 50 | + else |
| 51 | + { |
| 52 | + New-Item -ItemType directory -Path $output |
| 53 | + Write-Host "创建文件夹:$($output)" |
| 54 | + } |
| 55 | + |
| 56 | + $projs = @("OSharp", "OSharp.AspNetCore", "OSharp.Authorization.Datas", "OSharp.Authorization.Functions", |
| 57 | +"OSharp.AutoMapper", "OSharp.EntityFrameworkCore","OSharp.EntityFrameworkCore.MySql", "OSharp.EntityFrameworkCore.Oracle", |
| 58 | +"OSharp.EntityFrameworkCore.PostgreSql", "OSharp.EntityFrameworkCore.Sqlite","OSharp.EntityFrameworkCore.SqlServer", |
| 59 | +"OSharp.Exceptionless", "OSharp.Hangfire", "OSharp.Hosting.Apis", "OSharp.Hosting.Core", "OSharp.Hosting.EntityConfiguration", |
| 60 | +"OSharp.Identity", "OSharp.Log4Net", "OSharp.MiniProfiler", "OSharp.Redis", "OSharp.Swagger", "OSharp.Wpf") |
| 61 | + foreach($proj in $projs) |
| 62 | + { |
| 63 | + $path = "$($rootPath)/src/$($proj)/$($proj).csproj" |
| 64 | + dotnet build $path -c Release |
| 65 | + dotnet pack $path -c Release --output $output |
| 66 | + } |
| 67 | + |
| 68 | + $file = "$($rootPath)\build\OSharpNS.nuspec" |
| 69 | + nuget pack $file -OutputDirectory $output |
| 70 | + if($ENV:WORKSPACE -eq $null) |
| 71 | + { |
| 72 | + Invoke-Item $output |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +function PushNugetPackages() |
| 77 | +{ |
| 78 | + $output = "$($rootPath)\build\output" |
| 79 | + if(!(Test-Path $output)) |
| 80 | + { |
| 81 | + Write-Host "输出文件夹 $($output) 不存在" |
| 82 | + exit |
| 83 | + } |
| 84 | + Write-Host "正在查找 nupkg 发布包" |
| 85 | + $files = [System.IO.Directory]::GetFiles($output, "*.$($version)*nupkg") |
| 86 | + Write-Host "共找到 $($files.Length) 个版本号为 $($version) 的nuget文件" |
| 87 | + if($files.Length -eq 0) |
| 88 | + { |
| 89 | + exit |
| 90 | + } |
| 91 | + |
| 92 | + $server = "https://www.nuget.org" |
| 93 | + $items=@() |
| 94 | + foreach($file in $files) |
| 95 | + { |
| 96 | + $obj = New-Object PSObject -Property @{ |
| 97 | + Server = $server |
| 98 | + File = $file |
| 99 | + } |
| 100 | + $items += @($obj) |
| 101 | + } |
| 102 | + |
| 103 | + $items | ForEach-Object -Parallel { |
| 104 | + $item = $_ |
| 105 | + $name = [System.IO.Path]::GetFileName($item.File) |
| 106 | + Write-Host ("正在 {0} 向发布{1}" -f $item.Server, $name) |
| 107 | + $server = @("push", $item.File) + @("-Source", $item.Server) |
| 108 | + & nuget $server |
| 109 | + } -ThrottleLimit 5 |
| 110 | +} |
| 111 | + |
| 112 | +$now = [DateTime]::Now |
| 113 | +$rootPath = ($ENV:WORKSPACE) |
| 114 | +if($rootPath -eq $null) |
| 115 | +{ |
| 116 | + $rootPath = Split-Path -Parent $MyInvocation.MyCommand.Definition |
| 117 | + $rootPath = Split-Path -Parent $rootPath |
| 118 | +} |
| 119 | +Write-Host ("当前目录:$($rootPath)") |
| 120 | +$version = GetVersion |
| 121 | +Write-Host ("当前版本:$($version)") |
| 122 | +SetOsharpNSVersion |
| 123 | +BuildNugetPackages |
| 124 | +PushNugetPackages |
0 commit comments