优化打包逻辑
This commit is contained in:
@@ -32,7 +32,7 @@ using System.Runtime.InteropServices;
|
||||
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
|
||||
//通过使用 "*",如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyVersion("1.0.0.1")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.1")]
|
||||
|
||||
// NuGet包相关信息已在项目文件中配置
|
||||
|
||||
@@ -1,16 +1,37 @@
|
||||
# 托普瑞控制库发布脚本 请在 chcp 65001下运行
|
||||
|
||||
# 配置参数 - 基本设置
|
||||
$scriptDir = Get-Location
|
||||
# 使用PSScriptRoot获取脚本所在目录
|
||||
$scriptDir = $PSScriptRoot
|
||||
$output = Join-Path $scriptDir "Output"
|
||||
$server = "http://47.111.181.23:8081/repository/nuget-releases/"
|
||||
$key = "admin:admin"
|
||||
$actualDllName = "JoyD.Windows.CS.Toprie.dll"
|
||||
$targetDllName = "Toprie.dll"
|
||||
|
||||
# 从AssemblyInfo.cs获取版本号
|
||||
$assemblyInfoPath = "$scriptDir\Toprie\Properties\AssemblyInfo.cs"
|
||||
Write-Host "正在从 $assemblyInfoPath 获取版本号..."
|
||||
|
||||
if (-Not (Test-Path $assemblyInfoPath)) {
|
||||
Write-Host "错误: 找不到AssemblyInfo.cs文件!" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 读取文件内容并提取AssemblyFileVersion
|
||||
$assemblyInfoContent = Get-Content $assemblyInfoPath -Raw
|
||||
$versionMatch = [regex]::Match($assemblyInfoContent, '\[assembly: AssemblyFileVersion\("([\d\.]+)"\)\]')
|
||||
|
||||
if (-Not $versionMatch.Success) {
|
||||
Write-Host "错误: 无法从AssemblyInfo.cs中提取版本号!" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
$version = $versionMatch.Groups[1].Value
|
||||
Write-Host "成功获取版本号: $version" -ForegroundColor Green
|
||||
|
||||
# NuGet包元数据配置 - 在此处修改所有元数据
|
||||
$packageId = "com.joyd.toprie"
|
||||
$version = "1.0.0.0"
|
||||
$title = "托普瑞热像仪控制库"
|
||||
$authors = "曾庆明"
|
||||
$owners = "JoyD Technology"
|
||||
@@ -38,17 +59,27 @@ if (!(Test-Path $output)) {
|
||||
Write-Host "使用现有输出目录: $output"
|
||||
}
|
||||
|
||||
# 定义pdb和xml文件名称
|
||||
$actualPdbName = $actualDllName -replace "\.dll$", ".pdb"
|
||||
$actualXmlName = $actualDllName -replace "\.dll$", ".xml"
|
||||
$targetPdbName = $targetDllName -replace "\.dll$", ".pdb"
|
||||
$targetXmlName = $targetDllName -replace "\.dll$", ".xml"
|
||||
|
||||
# 清理之前的构建文件
|
||||
Write-Host "清理之前的构建文件.."
|
||||
if (Test-Path "$output\$actualDllName") { Remove-Item -Path "$output\$actualDllName" -Force }
|
||||
if (Test-Path "$output\$actualPdbName") { Remove-Item -Path "$output\$actualPdbName" -Force }
|
||||
if (Test-Path "$output\$actualXmlName") { Remove-Item -Path "$output\$actualXmlName" -Force }
|
||||
if (Test-Path "$output\$targetDllName") { Remove-Item -Path "$output\$targetDllName" -Force }
|
||||
if (Test-Path "$output\$targetPdbName") { Remove-Item -Path "$output\$targetPdbName" -Force }
|
||||
if (Test-Path "$output\$targetXmlName") { Remove-Item -Path "$output\$targetXmlName" -Force }
|
||||
if (Test-Path "$output\$nupkgFileName") { Remove-Item -Path "$output\$nupkgFileName" -Force }
|
||||
if (Test-Path "$output\$packageId.nuspec") { Remove-Item -Path "$output\$packageId.nuspec" -Force }
|
||||
|
||||
# 构建项目
|
||||
# 构建项目(确保生成pdb和xml文件)
|
||||
Write-Host "1. 正在构建项目..."
|
||||
Write-Host "当前目录: $scriptDir"
|
||||
dotnet build "$scriptDir\Toprie\Toprie.csproj" -c Release -o "$output"
|
||||
dotnet build "$scriptDir\Toprie\Toprie.csproj" -c Release -o "$output" /p:DebugSymbols=true /p:DebugType=full /p:DocumentationFile=true
|
||||
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "错误: 构建失败!" -ForegroundColor Red
|
||||
@@ -65,6 +96,17 @@ if (!(Test-Path "$output\$actualDllName")) {
|
||||
Copy-Item -Path "$output\$actualDllName" -Destination "$output\$targetDllName" -Force
|
||||
Write-Host "已将 $actualDllName 复制并重命名为$targetDllName 用于打包"
|
||||
|
||||
# 复制PDB和XML文件并重命名用于打包
|
||||
if (Test-Path "$output\$actualPdbName") {
|
||||
Copy-Item -Path "$output\$actualPdbName" -Destination "$output\$targetPdbName" -Force
|
||||
Write-Host "已将 $actualPdbName 复制并重命名为$targetPdbName 用于打包"
|
||||
}
|
||||
|
||||
if (Test-Path "$output\$actualXmlName") {
|
||||
Copy-Item -Path "$output\$actualXmlName" -Destination "$output\$targetXmlName" -Force
|
||||
Write-Host "已将 $actualXmlName 复制并重命名为$targetXmlName 用于打包"
|
||||
}
|
||||
|
||||
# 复制图标文件到输出目录
|
||||
if (Test-Path $iconSourcePath) {
|
||||
Copy-Item -Path $iconSourcePath -Destination (Join-Path $output $iconFileName) -Force
|
||||
@@ -133,6 +175,8 @@ $tempProjContent = @"
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="$targetDllName" Pack="true" PackagePath="lib\net40\$targetDllName" />
|
||||
<Content Include="$targetPdbName" Pack="true" PackagePath="lib\net40\$targetPdbName" />
|
||||
<Content Include="$targetXmlName" Pack="true" PackagePath="lib\net40\$targetXmlName" />
|
||||
<Content Include="$iconFileName" Pack="true" PackagePath="$iconFileName" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -177,6 +221,8 @@ $nuspecContent = @"
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="$targetDllName" target="lib\net40\" />
|
||||
<file src="$targetPdbName" target="lib\net40\" />
|
||||
<file src="$targetXmlName" target="lib\net40\" />
|
||||
<file src="$iconFileName" target="\" />
|
||||
</files>
|
||||
</package>
|
||||
@@ -206,6 +252,22 @@ $destDllPath = Join-Path $libDir $targetDllName
|
||||
Copy-Item -Path $sourceDllPath -Destination $destDllPath -Force
|
||||
Write-Host "已复制$sourceDllPath 到$destDllPath"
|
||||
|
||||
# 复制PDB文件到包结构中
|
||||
$sourcePdbPath = Join-Path $output $targetPdbName
|
||||
$destPdbPath = Join-Path $libDir $targetPdbName
|
||||
if (Test-Path $sourcePdbPath) {
|
||||
Copy-Item -Path $sourcePdbPath -Destination $destPdbPath -Force
|
||||
Write-Host "已复制$sourcePdbPath 到$destPdbPath"
|
||||
}
|
||||
|
||||
# 复制XML文件到包结构中
|
||||
$sourceXmlPath = Join-Path $output $targetXmlName
|
||||
$destXmlPath = Join-Path $libDir $targetXmlName
|
||||
if (Test-Path $sourceXmlPath) {
|
||||
Copy-Item -Path $sourceXmlPath -Destination $destXmlPath -Force
|
||||
Write-Host "已复制$sourceXmlPath 到$destXmlPath"
|
||||
}
|
||||
|
||||
# 复制图标文件到包结构根目录
|
||||
$sourceIconPath = Join-Path $output $iconFileName
|
||||
$destIconPath = Join-Path $tempDir $iconFileName
|
||||
|
||||
Reference in New Issue
Block a user