Skip to content

Commit 21bb619

Browse files
committed
更新nuget生成发布脚本
1 parent 7dd5ef0 commit 21bb619

File tree

6 files changed

+143
-19
lines changed

6 files changed

+143
-19
lines changed

Diff for: .gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ bld/
2525
[Ll]og/
2626

2727
/docs/_api
28-
/build/nupkgs
28+
/build/output
2929

3030
# Visual Studio 2015 cache/options directory
3131
.vs/

Diff for: OSharpNS.nuspec

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+


Diff for: build/nuget-build.ps1

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function GetVersion()
22
{
3-
$file = "./version.props"
3+
$file = "version.props"
44
$xml = New-Object -TypeName XML
55
$xml.Load($file)
66
$version = $xml.Project.PropertyGroup.Version
@@ -42,16 +42,16 @@ Write-Host ("当前版本:{0}" -f $version)
4242
SetOsharpNSVersion
4343

4444

45-
$nupkgs = ".\nupkgs"
46-
if(Test-Path $nupkgs)
45+
$output = ".\output"
46+
if(Test-Path $output)
4747
{
48-
Remove-Item ("{0}\*.*" -f $nupkgs)
49-
Write-Host ("清空 {0} 文件夹" -f $nupkgs)
48+
Remove-Item ("{0}\*.*" -f $output)
49+
Write-Host ("清空 {0} 文件夹" -f $output)
5050
}
5151
else
5252
{
53-
New-Item -Path . -Name $nupkgs -ItemType "directory" -Force
54-
Write-Host ("创建 {0} 文件夹" -f $nupkgs)
53+
New-Item -Path . -Name $output -ItemType "directory" -Force
54+
Write-Host ("创建 {0} 文件夹" -f $output)
5555
}
5656
$props = @("OSharp", "OSharp.AspNetCore", "OSharp.Authorization.Datas", "OSharp.Authorization.Functions",
5757
"OSharp.AutoMapper", "OSharp.EntityFrameworkCore","OSharp.EntityFrameworkCore.MySql", "OSharp.EntityFrameworkCore.Oracle",
@@ -62,9 +62,9 @@ foreach($prop in $props)
6262
{
6363
$path = ("../src/{0}/{0}.csproj" -f $prop)
6464
dotnet build $path -c Release
65-
dotnet pack $path -c Release --output $nupkgs
65+
dotnet pack $path -c Release --output $output
6666
}
6767

68-
nuget pack .\OSharpNS.nuspec -OutputDirectory $nupkgs
69-
Invoke-Item $nupkgs
68+
nuget pack .\OSharpNS.nuspec -OutputDirectory $output
69+
Invoke-Item $output
7070
pause

Diff for: build/nuget-push.ps1

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ Write-Host ("当前目录:{0}" -f $rootPath)
3333
$version = GetVersion
3434
Write-Host ("当前版本:{0}" -f $version)
3535

36-
$nupkgs = ("{0}\nupkgs" -f $rootPath)
37-
Write-Host $nupkgs
38-
if(!(Test-Path $nupkgs))
36+
$output = ("{0}\output" -f $rootPath)
37+
Write-Host $output
38+
if(!(Test-Path $output))
3939
{
40-
Write-Host ("输出文件夹 {0} 不存在" -f $nupkgs)
40+
Write-Host ("输出文件夹 {0} 不存在" -f $output)
4141
exit
4242
}
4343

44-
Set-Location $nupkgs
44+
Set-Location $output
4545
Write-Host ("`n正在查找nupkg发布包,当前目录:$(Get-Location)")
4646

47-
$files = [System.IO.Directory]::GetFiles($nupkgs, ("*.{0}*nupkg" -f $version))
47+
$files = [System.IO.Directory]::GetFiles($output, ("*.{0}*nupkg" -f $version))
4848
Write-Host ("共找到 {0} 个版本号为 {1} 的nupkg文件" -f $files.Length, $version)
4949
if($files.Length -eq 0){
5050
exit

Diff for: build/nuget.build.ps1

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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

Diff for: build/version.props

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
<VersionSuffixVersion>1207</VersionSuffixVersion>
77
<Version>$(VersionMain).$(VersionPrefix)$(VersionSuffix)$(VersionSuffixVersion)</Version>
88
<!--<Version>$(VersionMain).$(VersionPrefix)</Version>-->
9-
<!--<AssemblyVersion>$(VersionMain).$(VersionPrefix)</AssemblyVersion>-->
109
<FileVersion>$(VersionMain).$(VersionPrefix).$(VersionSuffixVersion)</FileVersion>
11-
<FileVersion>$(VersionMain).$(VersionPrefix)</FileVersion>
10+
<!--<FileVersion>$(VersionMain).$(VersionPrefix)</FileVersion>-->
1211
</PropertyGroup>
1312
</Project>

0 commit comments

Comments
 (0)