增加CSharp版的cubelib
This commit is contained in:
BIN
Windows/CS/Framework4.0/CubeLib/CubeLib.ico
Normal file
BIN
Windows/CS/Framework4.0/CubeLib/CubeLib.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
25
Windows/CS/Framework4.0/CubeLib/CubeLib.sln
Normal file
25
Windows/CS/Framework4.0/CubeLib/CubeLib.sln
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.36617.4
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CubeLib", "CubeLib\CubeLib.csproj", "{0AAA20B8-F8B1-4C09-ADBF-E6FD650EE9D4}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{0AAA20B8-F8B1-4C09-ADBF-E6FD650EE9D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{0AAA20B8-F8B1-4C09-ADBF-E6FD650EE9D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{0AAA20B8-F8B1-4C09-ADBF-E6FD650EE9D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0AAA20B8-F8B1-4C09-ADBF-E6FD650EE9D4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {7019BD3D-89E7-4B0D-85B6-9E26BD8EF151}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
71
Windows/CS/Framework4.0/CubeLib/CubeLib/CubeLib.csproj
Normal file
71
Windows/CS/Framework4.0/CubeLib/CubeLib/CubeLib.csproj
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{0AAA20B8-F8B1-4C09-ADBF-E6FD650EE9D4}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>JoyD.Windows.CS</RootNamespace>
|
||||||
|
<AssemblyName>JoyD.Windows.CS.CubeLib</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<Deterministic>true</Deterministic>
|
||||||
|
<TargetFrameworkProfile>
|
||||||
|
</TargetFrameworkProfile>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<DocumentationFile>bin\Debug\JoyD.Windows.CS.CubeLib.xml</DocumentationFile>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<ApplicationIcon>
|
||||||
|
</ApplicationIcon>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
<Reference Include="websocket-sharp, Version=1.0.1.0, Culture=neutral, PublicKeyToken=5660b08a1845a91e, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\WebSocketSharp-netstandard.1.0.1\lib\net35\websocket-sharp.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="WebSocket\IWebSocketClient.cs" />
|
||||||
|
<Compile Include="WebSocket\WebSocketClient.cs" />
|
||||||
|
<Compile Include="WebSocket\IWebSocketServer.cs" />
|
||||||
|
<Compile Include="WebSocket\WebSocketServer.cs" />
|
||||||
|
<Compile Include="WebSocket\WebSocketHelper.cs" />
|
||||||
|
<Compile Include="WebSocket\WebSocketTest.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="CubeLib.ico" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="packages.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="WebSocket\" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
||||||
BIN
Windows/CS/Framework4.0/CubeLib/CubeLib/CubeLib.ico
Normal file
BIN
Windows/CS/Framework4.0/CubeLib/CubeLib/CubeLib.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
@@ -0,0 +1,36 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// 有关程序集的一般信息由以下
|
||||||
|
// 控制。更改这些特性值可修改
|
||||||
|
// 与程序集关联的信息。
|
||||||
|
[assembly: AssemblyTitle("Net40通用控件库")]
|
||||||
|
[assembly: AssemblyDescription("包含WebSocket等控件")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("JoyD")]
|
||||||
|
[assembly: AssemblyProduct("com.joyd.CubeLib")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2025 JoyD")]
|
||||||
|
[assembly: AssemblyTrademark("JoyD")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||||
|
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||||
|
//请将此类型的 ComVisible 特性设置为 true。
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||||
|
[assembly: Guid("0aaa20b8-f8b1-4c09-adbf-e6fd650ee9d4")]
|
||||||
|
|
||||||
|
// 程序集的版本信息由下列四个值组成:
|
||||||
|
//
|
||||||
|
// 主版本
|
||||||
|
// 次版本
|
||||||
|
// 生成号
|
||||||
|
// 修订号
|
||||||
|
//
|
||||||
|
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
|
||||||
|
//通过使用 "*",如下所示:
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.1.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.1.0")]
|
||||||
374
Windows/CS/Framework4.0/CubeLib/publish-nuget.ps1
Normal file
374
Windows/CS/Framework4.0/CubeLib/publish-nuget.ps1
Normal file
@@ -0,0 +1,374 @@
|
|||||||
|
# 托普瑞控制库发布脚本 请在 chcp 65001下运行
|
||||||
|
|
||||||
|
# 配置参数 - 基本设置
|
||||||
|
$scriptDir = Get-Location
|
||||||
|
$output = Join-Path $scriptDir "Output"
|
||||||
|
$server = "http://47.111.181.23:8081/repository/nuget-releases/"
|
||||||
|
$key = "admin:admin"
|
||||||
|
$actualDllName = "JoyD.Windows.CS.Utils.dll"
|
||||||
|
$targetDllName = "JoyD.Windows.CS.Utils.dll" # 保持与AssemblyName一致,避免引用问题
|
||||||
|
|
||||||
|
# NuGet包元数据配置 - 在此处修改所有元数据
|
||||||
|
$packageId = "com.joyd.utils"
|
||||||
|
|
||||||
|
# 从AssemblyInfo.cs的AssemblyFileVersion获取版本号
|
||||||
|
$assemblyInfoPath = Join-Path $scriptDir "Utils\Properties\AssemblyInfo.cs"
|
||||||
|
if (Test-Path $assemblyInfoPath) {
|
||||||
|
$assemblyInfoContent = Get-Content -Path $assemblyInfoPath -Encoding UTF8 -Raw
|
||||||
|
|
||||||
|
# 只从AssemblyFileVersion获取版本号
|
||||||
|
$fileVersionMatch = [regex]::Match($assemblyInfoContent, '(?<!//)\[assembly: AssemblyFileVersion\("(.*?)"\)\]')
|
||||||
|
if ($fileVersionMatch.Success) {
|
||||||
|
$version = $fileVersionMatch.Groups[1].Value
|
||||||
|
Write-Host "从AssemblyFileVersion获取到版本号: $version"
|
||||||
|
} else {
|
||||||
|
Write-Host "错误: 无法从AssemblyInfo.cs的AssemblyFileVersion中获取版本号" -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host "错误: 找不到AssemblyInfo.cs文件" -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
$title = "通用工具库"
|
||||||
|
$authors = "曾庆明"
|
||||||
|
$owners = "JoyD Technology"
|
||||||
|
$description = "通用工具库,提供一些常用的工具函数和扩展方法"
|
||||||
|
$copyright = "Copyright 2025 JoyD Technology"
|
||||||
|
$tags = @("utils", "工具库")
|
||||||
|
$projectUrl = "https://github.com/joyd/utils"
|
||||||
|
$licenseUrl = "https://opensource.org/licenses/MIT"
|
||||||
|
$iconFileName = "Utils.ico"
|
||||||
|
$iconSourcePath = Join-Path $scriptDir $iconFileName
|
||||||
|
$iconUrl = "http://47.111.181.23:8081/repository/gradle/main/Utils.ico"
|
||||||
|
$releaseNotes = "取消区域性设置,默认使用 invariant culture"
|
||||||
|
|
||||||
|
# 其他设置
|
||||||
|
$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 }
|
||||||
|
# 添加清理pdb和xml文件
|
||||||
|
$actualPdbName = [System.IO.Path]::ChangeExtension($actualDllName, ".pdb")
|
||||||
|
$actualXmlName = [System.IO.Path]::ChangeExtension($actualDllName, ".xml")
|
||||||
|
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\$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\Utils\Utils.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
|
||||||
|
}
|
||||||
|
|
||||||
|
# 验证pdb和xml文件是否存在
|
||||||
|
$actualPdbName = [System.IO.Path]::ChangeExtension($actualDllName, ".pdb")
|
||||||
|
$actualXmlName = [System.IO.Path]::ChangeExtension($actualDllName, ".xml")
|
||||||
|
|
||||||
|
if (!(Test-Path "$output\$actualPdbName")) {
|
||||||
|
Write-Host "警告: 在输出目录中找不到$actualPdbName! 将继续打包但缺少调试信息" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(Test-Path "$output\$actualXmlName")) {
|
||||||
|
Write-Host "警告: 在输出目录中找不到$actualXmlName! 将继续打包但缺少文档注释" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
# 直接使用实际DLL文件,不进行重命名
|
||||||
|
Write-Host "使用实际DLL文件: $actualDllName 用于打包"
|
||||||
|
|
||||||
|
# 复制图标文件到输出目录
|
||||||
|
if (Test-Path $iconSourcePath) {
|
||||||
|
Copy-Item -Path $iconSourcePath -Destination (Join-Path $output $iconFileName) -Force
|
||||||
|
Write-Host "已复制图标文件到输出目录: $iconFileName"
|
||||||
|
} else {
|
||||||
|
Write-Host "警告: 图标文件 $iconSourcePath 不存在,将使用默认图标" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
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>$title</Title>
|
||||||
|
<Authors>$authors</Authors>
|
||||||
|
<Owners>$owners</Owners>
|
||||||
|
<Description>$description</Description>
|
||||||
|
<Copyright>$copyright</Copyright>
|
||||||
|
<PackageTags>$tagsString</PackageTags>
|
||||||
|
<PackageProjectUrl>$projectUrl</PackageProjectUrl>
|
||||||
|
<PackageLicenseUrl>$licenseUrl</PackageLicenseUrl>
|
||||||
|
<PackageIcon>$iconFileName</PackageIcon>
|
||||||
|
<PackageIconUrl></PackageIconUrl>
|
||||||
|
<PackageReleaseNotes>$releaseNotes</PackageReleaseNotes>
|
||||||
|
<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" />
|
||||||
|
<Content Include="$iconFileName" Pack="true" PackagePath="$iconFileName" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
|
"@
|
||||||
|
|
||||||
|
$tempProjPath = "$output\Temp.csproj"
|
||||||
|
Set-Content -Path $tempProjPath -Value $tempProjContent
|
||||||
|
|
||||||
|
# 在输出目录中创建包结构
|
||||||
|
Write-Host "3. 创建NuGet包.."
|
||||||
|
|
||||||
|
# 在输出目录中创建完整的nuspec文件
|
||||||
|
$nuspecPath = Join-Path $output "$packageId.nuspec"
|
||||||
|
|
||||||
|
# 将tags数组转换为空格分隔的字符串
|
||||||
|
$tagsString = $tags -join " "
|
||||||
|
|
||||||
|
$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>$title</title>
|
||||||
|
<authors>$authors</authors>
|
||||||
|
<owners>$owners</owners>
|
||||||
|
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||||
|
<description>$description</description>
|
||||||
|
<releaseNotes>$releaseNotes</releaseNotes>
|
||||||
|
<copyright>$copyright</copyright>
|
||||||
|
<tags>$tagsString</tags>
|
||||||
|
<projectUrl>$projectUrl</projectUrl>
|
||||||
|
<licenseUrl>$licenseUrl</licenseUrl>
|
||||||
|
<icon>$iconFileName</icon>
|
||||||
|
<iconUrl>$iconUrl</iconUrl>
|
||||||
|
<!-- 可以根据需要添加更多元数据,如依赖项、框架引用等 -->
|
||||||
|
<!-- <dependencies> -->
|
||||||
|
<!-- <group targetFramework=".NETFramework4.0"> -->
|
||||||
|
<!-- <dependency id="Newtonsoft.Json" version="13.0.1" /> -->
|
||||||
|
<!-- </group> -->
|
||||||
|
<!-- </dependencies> -->
|
||||||
|
</metadata>
|
||||||
|
<files>
|
||||||
|
<file src="$targetDllName" target="lib\net40\" />
|
||||||
|
<file src="$([System.IO.Path]::ChangeExtension($targetDllName, ".pdb"))" target="lib\net40\" />
|
||||||
|
<file src="$([System.IO.Path]::ChangeExtension($targetDllName, ".xml"))" target="lib\net40\" />
|
||||||
|
<file src="$iconFileName" target="\" />
|
||||||
|
</files>
|
||||||
|
</package>
|
||||||
|
"@
|
||||||
|
|
||||||
|
Set-Content -Path $nuspecPath -Value $nuspecContent -Encoding UTF8
|
||||||
|
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"
|
||||||
|
|
||||||
|
# 复制pdb文件到包结构中
|
||||||
|
$targetPdbName = [System.IO.Path]::ChangeExtension($targetDllName, ".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文件到包结构中
|
||||||
|
$targetXmlName = [System.IO.Path]::ChangeExtension($targetDllName, ".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
|
||||||
|
if (Test-Path $sourceIconPath) {
|
||||||
|
Copy-Item -Path $sourceIconPath -Destination $destIconPath -Force
|
||||||
|
Write-Host "已复制图标文件到包结构: $destIconPath"
|
||||||
|
} else {
|
||||||
|
Write-Host "警告: 在输出目录中找不到图标文件 $sourceIconPath" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
# 创建[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'/><Default Extension='png' ContentType='image/png'/><Default Extension='ico' ContentType='image/x-icon'/></Types>"
|
||||||
|
Write-Host "已在 $contentTypesPath 创建[Content_Types].xml"
|
||||||
|
|
||||||
|
# 复制nuspec文件到包结构根目录
|
||||||
|
$sourceNuspecPath = Join-Path $output "$packageId.nuspec"
|
||||||
|
$destNuspecPath = Join-Path $tempDir "$packageId.nuspec"
|
||||||
|
if (Test-Path $sourceNuspecPath) {
|
||||||
|
Copy-Item -Path $sourceNuspecPath -Destination $destNuspecPath -Force
|
||||||
|
Write-Host "已复制nuspec文件到包结构: $destNuspecPath"
|
||||||
|
} else {
|
||||||
|
Write-Host "警告: 找不到nuspec文件 $sourceNuspecPath" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
# 创建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 "标题: $title"
|
||||||
|
Write-Host "作者: $authors"
|
||||||
|
Write-Host "所有者: $owners"
|
||||||
|
Write-Host "描述: $description"
|
||||||
|
Write-Host "标签: $tagsString"
|
||||||
|
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 "发布过程完成"
|
||||||
Reference in New Issue
Block a user