添加发布脚本

This commit is contained in:
zqm
2025-10-23 11:16:35 +08:00
parent 5ad98161d7
commit 810cb1c344
13 changed files with 374 additions and 11 deletions

View File

@@ -0,0 +1 @@
/Test

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>com.joyd.toprie</id>
<version>1.0.0.0</version>
<title>Toprie Thermal Camera Control</title>
<authors>JoyD</authors>
<description>Thermal camera control library</description>
<copyright>Copyright 2025</copyright>
</metadata>
<files>
<file src="Toprie.dll" target="lib\net40\" />
</files>
</package>

Binary file not shown.

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>com.joyd.toprie</id>
<version>1.0.0.0</version>
<title>Toprie Thermal Camera Control</title>
<authors>JoyD</authors>
<description>Thermal camera control library</description>
<copyright>Copyright 2025</copyright>
</metadata>
<files>
<file src="Toprie.dll" target="lib\net40\" />
</files>
</package>

View File

@@ -0,0 +1,48 @@
@echo off
echo 开始打包和发布NuGet包...
REM 设置参数
set VERSION=1.0.0.0
set PACKAGE_ID=com.joyd.toprie
set DLL_PATH=Toprie.dll
set NUGET_SERVER=http://47.111.181.23:8081/repository/nuget-releases/
set API_KEY=admin:admin
REM 创建临时项目文件
(echo <Project Sdk="Microsoft.NET.Sdk">
echo <PropertyGroup>
echo <TargetFramework>net40</TargetFramework>
echo <PackageId>%PACKAGE_ID%</PackageId>
echo <Version>%VERSION%</Version>
echo <Title>Toprie Thermal Camera Control</Title>
echo <Authors>JoyD</Authors>
echo <Description>Thermal camera control library</Description>
echo <Copyright>Copyright 2025</Copyright>
echo <PackageOutputPath>.</PackageOutputPath>
echo </PropertyGroup>
echo <ItemGroup>
echo <Content Include="%DLL_PATH%" Pack="true" PackagePath="lib\net40\%DLL_PATH%" />
echo </ItemGroup>
echo </Project>) > Temp.csproj
REM 打包
nuget pack Temp.csproj -Build -Properties Configuration=Release
REM 发布
for %%f in (*.nupkg) do (
echo 发布包: %%f
nuget push %%f %API_KEY% -Source %NUGET_SERVER%
if not errorlevel 1 (
echo 发布成功!
exit /b 0
) else (
echo 发布失败,但包已创建: %%f
)
)
echo 清理临时文件
if exist Temp.csproj del Temp.csproj
echo 发布脚本执行完成。
pause

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="allowInsecureConnections" value="true" />
</config>
<packageSources>
<add key="JoyD-Private" value="http://47.111.181.23:8081/repository/nuget-hosted/" />
</packageSources>
<packageSourceCredentials>
<JoyD-Private>
<add key="Username" value="admin" />
<add key="Password" value="YWRtaW46YWRtaW4=" />
</JoyD-Private>
</packageSourceCredentials>
</configuration>

View File

@@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.36324.19
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Toprie", "Toprie\Toprie.csproj", "{E078D2E2-7F70-4C68-90A5-99FA66E62F9D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{C309F3A2-0E77-42E4-BE3D-1448E7DFA433}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
{E078D2E2-7F70-4C68-90A5-99FA66E62F9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E078D2E2-7F70-4C68-90A5-99FA66E62F9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E078D2E2-7F70-4C68-90A5-99FA66E62F9D}.Release|Any CPU.Build.0 = Release|Any CPU
{C309F3A2-0E77-42E4-BE3D-1448E7DFA433}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C309F3A2-0E77-42E4-BE3D-1448E7DFA433}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C309F3A2-0E77-42E4-BE3D-1448E7DFA433}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C309F3A2-0E77-42E4-BE3D-1448E7DFA433}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -1,4 +1,4 @@
namespace Toprie
namespace JoyD.Windows.CS.Toprie
{
partial class Camera
{

View File

@@ -7,7 +7,7 @@ using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Toprie
namespace JoyD.Windows.CS.Toprie
{
public partial class Camera : UserControl
{

View File

@@ -1,17 +1,17 @@
using System.Reflection;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Toprie")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyTitle("托普瑞热像仪控件库")]
[assembly: AssemblyDescription("托普瑞热像仪控件库,提供热像仪图像显示和控制功能")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Toprie")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCompany("JoyD")]
[assembly: AssemblyProduct("com.joyd.toprie")]
[assembly: AssemblyCopyright("Copyright © 2025 JoyD")]
[assembly: AssemblyTrademark("JoyD")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
@@ -34,3 +34,5 @@ using System.Runtime.InteropServices;
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
// NuGet包相关信息已在项目文件中配置

View File

@@ -7,11 +7,29 @@
<ProjectGuid>{E078D2E2-7F70-4C68-90A5-99FA66E62F9D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Toprie</RootNamespace>
<AssemblyName>Toprie</AssemblyName>
<RootNamespace>JoyD.Windows.CS</RootNamespace>
<AssemblyName>JoyD.Windows.CS.Toprie</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<!-- NuGet包信息 -->
<PackageId>com.joyd.toprie</PackageId>
<Version>1.0.0.0</Version>
<Authors>JoyD</Authors>
<Description>托普瑞热像仪控件库,提供热像仪图像显示和控制功能</Description>
<Copyright>Copyright © 2025 JoyD</Copyright>
<PackageProjectUrl>http://joyd.com/</PackageProjectUrl>
<RepositoryUrl>http://joyd.com/repo/toprie</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<IncludeBuildOutput>true</IncludeBuildOutput>
<IncludeContentInPack>true</IncludeContentInPack>
</PropertyGroup>
<!-- 添加NuGet打包支持 -->
<Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" />
<!-- 确保项目支持pack目标 -->
<PropertyGroup>
<IsPackable>true</IsPackable>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

View File

@@ -0,0 +1,245 @@
# 托普瑞控制库发布脚本 请在 chcp 65001下运行
# 配置参数
$scriptDir = Get-Location
$output = Join-Path $scriptDir "Output"
$server = "http://47.111.181.23:8081/repository/nuget-releases/"
$key = "admin:admin"
$packageId = "com.joyd.toprie"
$version = "1.0.0.0"
$actualDllName = "JoyD.Windows.CS.Toprie.dll"
$targetDllName = "Toprie.dll"
$nupkgFileName = "$packageId.$version.nupkg"
$nupkgFilePath = Join-Path $output $nupkgFileName
Write-Host "========== 托普瑞库发布开始 =========="
# 创建输出目录
if (!(Test-Path $output)) {
New-Item -ItemType Directory -Path $output -Force | Out-Null
Write-Host "已创建输出目录: $output"
} else {
Write-Host "使用现有输出目录: $output"
}
# 清理之前的构建文件
Write-Host "清理之前的构建文件.."
if (Test-Path "$output\$actualDllName") { Remove-Item -Path "$output\$actualDllName" -Force }
if (Test-Path "$output\$targetDllName") { Remove-Item -Path "$output\$targetDllName" -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 }
# 构建项目
Write-Host "1. 正在构建项目..."
Write-Host "当前目录: $scriptDir"
dotnet build "$scriptDir\Toprie\Toprie.csproj" -c Release -o "$output"
if ($LASTEXITCODE -ne 0) {
Write-Host "错误: 构建失败!" -ForegroundColor Red
exit 1
}
# 验证DLL是否存在
if (!(Test-Path "$output\$actualDllName")) {
Write-Host "错误: 在输出目录中找不到$actualDllName!" -ForegroundColor Red
exit 1
}
# 复制DLL并重命名用于打包
Copy-Item -Path "$output\$actualDllName" -Destination "$output\$targetDllName" -Force
Write-Host "已将 $actualDllName 复制并重命名为$targetDllName 用于打包"
Write-Host "2. 准备打包文件..."
# 在Output目录创建NuGet.Config文件这样dotnet nuget push命令就能正确找到它
$localNugetConfigPath = Join-Path -Path $output -ChildPath "NuGet.Config"
# 创建包含全面配置的NuGet.Config文件
$nugetConfigContent = @"
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="allowInsecureConnections" value="true" />
<add key="DefaultPushSource" value="$server" />
</config>
<packageSources>
<add key="JoyD-Private" value="$server" />
</packageSources>
<packageSourceMapping>
<packageSource key="JoyD-Private">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
<packageSourceCredentials>
<JoyD-Private>
<add key="Username" value="admin" />
<add key="Password" value="YWRtaW46YWRtaW4=" />
</JoyD-Private>
</packageSourceCredentials>
</configuration>
"@
# 设置配置文件
Set-Content -Path $localNugetConfigPath -Value $nugetConfigContent
Write-Host "已在Output目录设置NuGet.Config: $localNugetConfigPath"
# 创建一个简单的.csproj文件用于打包无需还原
$tempProjContent = @"
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net40</TargetFramework>
<PackageId>$packageId</PackageId>
<Version>$version</Version>
<Title>Toprie Thermal Camera Control</Title>
<Authors>JoyD</Authors>
<Description>Thermal camera control library</Description>
<Copyright>Copyright 2025</Copyright>
<PackageOutputPath>.</PackageOutputPath>
<RestorePackagesConfig>true</RestorePackagesConfig>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IsPackable>true</IsPackable>
<NoBuild>true</NoBuild>
</PropertyGroup>
<ItemGroup>
<Content Include="$targetDllName" Pack="true" PackagePath="lib\net40\$targetDllName" />
</ItemGroup>
</Project>
"@
$tempProjPath = "$output\Temp.csproj"
Set-Content -Path $tempProjPath -Value $tempProjContent
# 在输出目录中创建包结构
Write-Host "3. 创建NuGet包.."
# 在输出目录中创建简化的nuspec文件
$nuspecPath = Join-Path $output "$packageId.nuspec"
$nuspecContent = @"
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>$packageId</id>
<version>$version</version>
<title>Toprie Thermal Camera Control</title>
<authors>JoyD</authors>
<description>Thermal camera control library</description>
<copyright>Copyright 2025</copyright>
</metadata>
<files>
<file src="$targetDllName" target="lib\net40\" />
</files>
</package>
"@
Set-Content -Path $nuspecPath -Value $nuspecContent
Write-Host "已创建nuspec文件: $nuspecPath"
# 手动创建nupkg包结构
Write-Host "创建包结构.."
$tempDir = Join-Path $output "temp_pkg"
# 确保临时目录存在
if (!(Test-Path $tempDir)) {
New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
}
# 创建lib/net40子目录
$libDir = Join-Path $tempDir "lib\net40"
if (!(Test-Path $libDir)) {
New-Item -ItemType Directory -Path $libDir -Force | Out-Null
}
# 复制DLL到包结构中
$sourceDllPath = Join-Path $output $targetDllName
$destDllPath = Join-Path $libDir $targetDllName
Copy-Item -Path $sourceDllPath -Destination $destDllPath -Force
Write-Host "已复制$sourceDllPath$destDllPath"
# 创建[Content_Types].xml文件有效nupkg必需
$contentTypesPath = Join-Path $tempDir "[Content_Types].xml"
# 使用-LiteralPath参数避免方括号被解释为通配符
Set-Content -LiteralPath $contentTypesPath -Value "<?xml version='1.0' encoding='utf-8'?><Types xmlns='http://schemas.openxmlformats.org/package/2006/content-types'><Default Extension='dll' ContentType='application/octet-stream'/><Default Extension='xml' ContentType='application/xml'/></Types>"
Write-Host "已在 $contentTypesPath 创建[Content_Types].xml"
# 创建zip文件并将其重命名为nupkg
$zipPath = Join-Path $output "temp_manual.zip"
# 清理任何现有文件
if (Test-Path $zipPath) {
Remove-Item -Path $zipPath -Force
Write-Host "已移除现有的zip文件"
}
if (Test-Path $nupkgFilePath) {
Remove-Item -Path $nupkgFilePath -Force
Write-Host "已移除现有的nupkg文件"
}
Write-Host "$tempDir\* 创建zip归档到$zipPath..."
Compress-Archive -Path "$tempDir\*" -DestinationPath $zipPath -Force
if (Test-Path $zipPath) {
Write-Host "正在将$zipPath 重命名为 $nupkgFilePath..."
Rename-Item -Path $zipPath -NewName $nupkgFileName -Force
if (Test-Path $nupkgFilePath) {
$nupkgFile = Get-Item $nupkgFilePath
Write-Host "✅ 成功创建包: $($nupkgFile.FullName)"
Write-Host "包大小: $([math]::Round($nupkgFile.Length / 1KB, 2)) KB"
}
}
# 清理临时文件夹
Remove-Item -Path $tempDir -Recurse -Force
Write-Host "已清理临时文件夹"
# 检查包文件是否存在
if (Test-Path $nupkgFilePath) {
$nupkgFile = Get-Item $nupkgFilePath
Write-Host "找到包文件: $($nupkgFile.FullName)"
Write-Host "4. 正在发布包到仓库..."
# 使用curl直接发布到HTTP仓库
Write-Host "使用curl直接发布到HTTP仓库..."
# 构建curl命令
$curlCommand = "curl.exe -X PUT -u $key -F package=@$nupkgFilePath $server"
Write-Host "正在执行: $curlCommand"
# 执行curl命令使用curl.exe避免PowerShell别名冲突
& curl.exe -X PUT -u $key -F package=@$nupkgFilePath $server
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ 成功: 包发布成功" -ForegroundColor Green
Write-Host "包ID: $packageId"
Write-Host "版本: $version"
Write-Host "仓库: $server"
} else {
Write-Host "❌ 错误: 包创建成功但发布失败" -ForegroundColor Red
Write-Host "包文件位置: $($nupkgFile.FullName)"
Write-Host "
您可以尝试手动发布使用curl命令"
Write-Host "curl -X PUT -u admin:admin -F \"package=@$($nupkgFile.FullName)\" $server"
Write-Host "
或者直接在项目中使用创建的包文件"
}
} else {
Write-Host "❌ 错误: 未创建NuGet包" -ForegroundColor Red
Write-Host "请检查dotnet CLI是否正确配置"
Write-Host "您可以尝试使用Output目录中的文件手动创建包"
}
# 最终清理
Write-Host "正在执行最终清理.."
if (Test-Path "$output\Temp.csproj") {
Remove-Item -Path "$output\Temp.csproj" -Force
Write-Host "已移除Temp.csproj"
}
# 删除我们在Output目录创建的NuGet.Config文件
if (Test-Path $localNugetConfigPath) {
Remove-Item -Path $localNugetConfigPath -Force
Write-Host "已删除临时创建的NuGet.Config"
}
Write-Host "
发布过程完成"