PackageProvider

本文介绍了Struts框架中XML配置文件的元素及其作用,包括如何通过PackageProvider加载配置生成PackageConfig对象,并最终形成RuntimeConfiguration。此外,还详细解释了struts.xml文件中各个配置项的具体含义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PackageProvider 用于将struts xml中的package元素转成PackageConfig对象。

 

 由DefaultConfiguration 调用PackageProvider.loadPackages()方法,生成多个PackageConfig对象。

DefaultConfiguration 对PackageConfig对象处理生成RuntimeConfiguration。

 

RuntimeConfiguration在struts处理请求流程中被使用,struts解析请求的url而生成namesapce 和 actionName,从RuntimeConfiguration就可以获取对应Action的配置信息ActionConfig. 

 

 



 strus中 xml的配置元素:

 

<struts>  
    <!--用于对bean的定义,置于Contatiner中-->  
    <bean type="类型" name="实现类名称(为空则取默认值default)" class="实现类全路径" static="true/false(是否只是静态注入)" scope="default|request|session|singleton|thread"/>  
      
    <constant name="param1" value="value1">   
    <!--用于对bean参数的配置Contatiner中,可以代替properties文件-->  
      
      
 <package name="包名" namespace="/ 或 /xxx 或 /xxx/yyy " extends="struts-default(多个用逗号分隔,自动继承)" abstract="true/false (true:被子类扩展时才能被使用)" strict-method-invocation="">  
             <result-types>  
                <result-type name="结果类型名称" class="结果类型实现类" default="是否为默认的">  
                    <param name="param1">value1</param>  
                </result-type>  
              </result-types>  
            <interceptors>  
                <interceptor name="栏截器名称" class="栏截器实现类" >  
                        <param name="param1">value1</param>  
                </interceptor>      
          </interceptors>  
            <interceptor-stack name="栏截器堆栈名称">  
                    <interceptor-ref name="栏截器名称1|栏截器堆栈名称1">  
                        <param name="param1">value1</param>  
                    </interceptor-ref>  
                  <interceptor-ref name="栏截器名称2|栏截器堆栈名称2">  
                    <interceptor-ref name="栏截器名称3||栏截器堆栈名称3">  
          </interceptor-stack>  
          <interceptor-stack name="">  
                    。。。。。。  
          </interceptor-stack>  
            
          <default-interceptor-ref name="栏截器名称|栏截器堆栈名称">  
            <default-class-ref class=""/>  
              
       <global-results>  
           <result name="ACTION的返回值(不设置默认取success)" type="结果类型名称(如果为空则取本包或父包中result-type.default=true的)">  
            [<param name="param1">value1</param>|value值(需要result-type.class类中有DEFAULT_PARAM = 默认参数名,来对应value值)  ]  
           </result>  
       </global-results>  
  
  
       <global-exception-mappings>  
           <exception-mapping name ="为空取result属性" exception="java.lang.Exception" result="对应global-results.result.name">  
            <param name="param1">value1</param>  
           </exception-mapping>  
       </global-exception-mappings>  
  
       <action name="支持通配符 (如[*!*|*_*|User_*]),在method 或result中可以使用{1}或{2}表示第一个或第二个通配符值" class="如果未配置则取default-class" method="未定义则从url中获取,未取到则使用execute">  
            <result name="ACTION的返回值(不设置默认取success)" type="结果类型名称(如果为空则取result-type.default=true的)">  
            [<param name="param1">value1</param>|value值(需要result-type.class类中有DEFAULT_PARAM = 默认参数名,来对应value值)  ]  
           </result>  
            <!--本pagckage 和父package 中的global-results中的result 自动被添加进来 -->
            
           <exception-mapping name ="为空取result属性" exception="java.lang.Exception" result="对应action-results.result.name 或 global-results.result.name">  
            <param name="param1">value1</param>  
           </exception-mapping>
           <!--本pagckage 和父package 中的global-exception-mappings中的exception-mapping 自动被添加进来-->  
           
           
           <interceptor-ref name="栏截器名称1">  
                        <param name="param1">value1</param>(用于覆盖“栏截器名称1”定义时的参数)  
                    <interceptor-ref name="栏截器堆栈名称1">  
                        <param name="堆栈内栏截器名称1.param1">value1</param>(用于覆盖(栏截器堆栈名称1中某个栏截器)定义时的参数)  
                    </interceptor-ref> 
                    <!--如果未定义interceptor,则从本包中取默认的拦截器,没有默认则到父包中找--> 
                    
                    <allowed-methods>  
                    允许的方法名,多个方法名用逗号分隔  
                  </allowed-methods>  
       </action>  
         
       <default-action-ref name="name">  
   </package>  
   </struts>  
     

 

PS C:\Users\Administrator> Install-Module -Name Pester -Force -SkipPublisherCheck >> 需需要要使使用用 NuGet 提提供供程程序序来来继继续续操操作作 PowerShellGet 需需要要使使用用 NuGet 提提供供程程序序““2.8.5.201””或或更更高高版版本本来来与与基基于于 NuGet 的的存存储储库库交交互互。。必必须须在在““C:\Program Files\PackageManagement\ProviderAssemblies””或或““C:\Users\Administrator\AppData\Local\PackageManagement\ProviderAssemblies”” 中提供 NuGet 提供程序。也可以通过运行 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force' 安装 NuGet 提供程序。是否要让 PowerShellGet 立即安装并导入 NuGet 提供程序? [Y] 是(Y) [N] 否(N) [S] 暂停(S) [?] 帮助 (默认值为“Y”): y PS C:\Users\Administrator> PS C:\Users\Administrator> PS C:\Users\Administrator> # 执行所有测试 >> Invoke-Pester -Path "E:\CurlTools\Modules\Tests\CurlTools.Tests.ps1" >> >> # 输出示例 >> Describing 模块加载测试 >> [+] 应成功导入模块 102ms >> [+] 应导出Get-CurlPath函数 41ms >> [+] 应正确检测curl.exe路径 35ms >> >> Describing 核心功能测试 >> [+] Get-CurlPath返回有效的可执行文件路径 52ms >> [+] Get-CurlVersion返回版本信息 78ms >> [+] Invoke-SecureDownload成功下载文件 1.2s >> [+] 优雅处理无效URL 45ms >> >> Describing 安全策略测试 >> [+] 应拒绝未授权域名 32ms >> [+] 应允许github.com下载 890ms >> 所在位置 行:6 字符: 4 + [+] 应成功导入模块 102ms + ~ "[" 后面缺少类型名称。 所在位置 行:7 字符: 4 + [+] 应导出Get-CurlPath函数 41ms + ~ "[" 后面缺少类型名称。 所在位置 行:8 字符: 4 + [+] 应正确检测curl.exe路径 35ms + ~ "[" 后面缺少类型名称。 所在位置 行:11 字符: 4 + [+] Get-CurlPath返回有效的可执行文件路径 52ms + ~ "[" 后面缺少类型名称。 所在位置 行:12 字符: 4 + [+] Get-CurlVersion返回版本信息 78ms + ~ "[" 后面缺少类型名称。 所在位置 行:13 字符: 4 + [+] Invoke-SecureDownload成功下载文件 1.2s + ~ "[" 后面缺少类型名称。 所在位置 行:14 字符: 4 + [+] 优雅处理无效URL 45ms + ~ "[" 后面缺少类型名称。 所在位置 行:17 字符: 4 + [+] 应拒绝未授权域名 32ms + ~ "[" 后面缺少类型名称。 所在位置 行:18 字符: 4 + [+] 应允许github.com下载 890ms + ~ "[" 后面缺少类型名称。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingTypename PS C:\Users\Administrator> name: CurlTools CI >> >> on: [push, pull_request] >> >> jobs: >> test: >> runs-on: windows-latest >> steps: >> - uses: actions/checkout@v2 >> - name: Setup PowerShell >> uses: actions/setup-powershell@v1 >> with: >> pwsh: true >> - name: Run Pester tests >> run: | >> Install-Module Pester -Force -AllowClobber >> Invoke-Pester -Path .\Modules\Tests\ -OutputFile TestResults.xml -OutputFormat NUnitXml >> - name: Publish test results >> uses: actions/upload-artifact@v2 >> with: >> name: TestResults >> path: TestResults.xml >> 所在位置 行:9 字符: 6 + - uses: actions/checkout@v2 + ~ 一元运算符“-”后面缺少表达式。 所在位置 行:9 字符: 7 + - uses: actions/checkout@v2 + ~~~~~ 表达式或语句中包含意外的标记“uses:”。 所在位置 行:10 字符: 6 + - name: Setup PowerShell + ~ 一元运算符“-”后面缺少表达式。 所在位置 行:10 字符: 7 + - name: Setup PowerShell + ~~~~~ 表达式或语句中包含意外的标记“name:”。 所在位置 行:14 字符: 6 + - name: Run Pester tests + ~ 一元运算符“-”后面缺少表达式。 所在位置 行:14 字符: 7 + - name: Run Pester tests + ~~~~~ 表达式或语句中包含意外的标记“name:”。 所在位置 行:18 字符: 6 + - name: Publish test results + ~ 一元运算符“-”后面缺少表达式。 所在位置 行:18 字符: 7 + - name: Publish test results + ~~~~~ 表达式或语句中包含意外的标记“name:”。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingExpressionAfterOperator PS C:\Users\Administrator> It "应处理大文件下载" { >> # 测试>1GB文件下载 >> } >> >> It "应验证文件哈希" { >> # 测试哈希校验功能 >> } >> >> It "应限制下载速度" { >> # 测试限速功能 >> } >> 不能对 Null 值表达式调用方法。 所在位置 C:\Program Files\WindowsPowerShell\Modules\Pester\5.7.1\Pester.psm1:1026 字符: 35 + ... ath = @(<# Get full name #> $history = $state.Stack.ToArray(); [Array ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [],RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull 使用“1”个参数调用“Reverse”时发生异常:“值不能为 null。 参数名: array” 所在位置 C:\Program Files\WindowsPowerShell\Modules\Pester\5.7.1\Pester.psm1:1026 字符: 70 + ... $history = $state.Stack.ToArray(); [Array]::Reverse($history); $histo ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ArgumentNullException 不能对 Null 值表达式调用方法。 所在位置 C:\Program Files\WindowsPowerShell\Modules\Pester\5.7.1\Pester.psm1:1051 字符: 5 + $state.CurrentBlock.Tests.Add($Test) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [],RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull 不能对 Null 值表达式调用方法。 所在位置 C:\Program Files\WindowsPowerShell\Modules\Pester\5.7.1\Pester.psm1:1052 字符: 5 + $state.CurrentBlock.Order.Add($Test) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [],RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull 不能对 Null 值表达式调用方法。 所在位置 C:\Program Files\WindowsPowerShell\Modules\Pester\5.7.1\Pester.psm1:1026 字符: 35 + ... ath = @(<# Get full name #> $history = $state.Stack.ToArray(); [Array ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [],RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull 使用“1”个参数调用“Reverse”时发生异常:“值不能为 null。 参数名: array” 所在位置 C:\Program Files\WindowsPowerShell\Modules\Pester\5.7.1\Pester.psm1:1026 字符: 70 + ... $history = $state.Stack.ToArray(); [Array]::Reverse($history); $histo ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ArgumentNullException 不能对 Null 值表达式调用方法。 所在位置 C:\Program Files\WindowsPowerShell\Modules\Pester\5.7.1\Pester.psm1:1051 字符: 5 + $state.CurrentBlock.Tests.Add($Test) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [],RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull 不能对 Null 值表达式调用方法。 所在位置 C:\Program Files\WindowsPowerShell\Modules\Pester\5.7.1\Pester.psm1:1052 字符: 5 + $state.CurrentBlock.Order.Add($Test) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [],RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull 不能对 Null 值表达式调用方法。 所在位置 C:\Program Files\WindowsPowerShell\Modules\Pester\5.7.1\Pester.psm1:1026 字符: 35 + ... ath = @(<# Get full name #> $history = $state.Stack.ToArray(); [Array ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [],RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull 使用“1”个参数调用“Reverse”时发生异常:“值不能为 null。 参数名: array” 所在位置 C:\Program Files\WindowsPowerShell\Modules\Pester\5.7.1\Pester.psm1:1026 字符: 70 + ... $history = $state.Stack.ToArray(); [Array]::Reverse($history); $histo ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ArgumentNullException 不能对 Null 值表达式调用方法。 所在位置 C:\Program Files\WindowsPowerShell\Modules\Pester\5.7.1\Pester.psm1:1051 字符: 5 + $state.CurrentBlock.Tests.Add($Test) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [],RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull 不能对 Null 值表达式调用方法。 所在位置 C:\Program Files\WindowsPowerShell\Modules\Pester\5.7.1\Pester.psm1:1052 字符: 5 + $state.CurrentBlock.Order.Add($Test) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [],RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull PS C:\Users\Administrator> It "应处理网络中断" { >> # 使用Fiddler或Charles模拟网络中断 >> } >> 不能对 Null 值表达式调用方法。 所在位置 C:\Program Files\WindowsPowerShell\Modules\Pester\5.7.1\Pester.psm1:1026 字符: 35 + ... ath = @(<# Get full name #> $history = $state.Stack.ToArray(); [Array ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [],RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull 使用“1”个参数调用“Reverse”时发生异常:“值不能为 null。 参数名: array” 所在位置 C:\Program Files\WindowsPowerShell\Modules\Pester\5.7.1\Pester.psm1:1026 字符: 70 + ... $history = $state.Stack.ToArray(); [Array]::Reverse($history); $histo ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ArgumentNullException 不能对 Null 值表达式调用方法。 所在位置 C:\Program Files\WindowsPowerShell\Modules\Pester\5.7.1\Pester.psm1:1051 字符: 5 + $state.CurrentBlock.Tests.Add($Test) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [],RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull 不能对 Null 值表达式调用方法。 所在位置 C:\Program Files\WindowsPowerShell\Modules\Pester\5.7.1\Pester.psm1:1052 字符: 5 + $state.CurrentBlock.Order.Add($Test) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [],RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull PS C:\Users\Administrator>
最新发布
08-15
PS C:\Users\Administrator> # 获取当前 curl 路径 >> Get-CurlPath >> >> # 设置自定义 curl 路径 >> Set-CurlPath -Path "C:\Custom\Curl\Path" >> >> # 获取 curl 版本信息 >> Get-CurlVersion >> Get-CurlPath : 无法将“Get-CurlPath”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径 ,请确保路径正确,然后再试一次。 所在位置 行:2 字符: 1 + Get-CurlPath + ~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-CurlPath:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException Set-CurlPath : 无法将“Set-CurlPath”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径 ,请确保路径正确,然后再试一次。 所在位置 行:5 字符: 1 + Set-CurlPath -Path "C:\Custom\Curl\Path" + ~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Set-CurlPath:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException Get-CurlVersion : 无法将“Get-CurlVersion”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包 括路径,请确保路径正确,然后再试一次。 所在位置 行:8 字符: 1 + Get-CurlVersion + ~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-CurlVersion:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\Administrator> # 基本下载 >> Invoke-SecureDownload -Url "https://example.com/file.zip" -OutputPath "C:\Downloads\file.zip" >> >> # 带哈希验证的下载 >> $expectedHash = "2a5f3c8d9e1b4a7c6d9f0e1a2b3c4d5e6f7a8b9c0" >> Invoke-SecureDownload -Url "https://example.com/file.zip" ` >> -OutputPath "C:\Downloads\file.zip" ` >> -ExpectedHash $expectedHash ` >> -HashAlgorithm SHA256 >> Invoke-SecureDownload : 无法将“Invoke-SecureDownload”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的 拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:2 字符: 1 + Invoke-SecureDownload -Url "https://example.com/file.zip" -OutputPath ... + ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Invoke-SecureDownload:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException Invoke-SecureDownload : 无法将“Invoke-SecureDownload”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的 拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:6 字符: 1 + Invoke-SecureDownload -Url "https://example.com/file.zip" ` + ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Invoke-SecureDownload:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\Administrator> CurlTools/ >> ├── CurlTools.psd1 # 模块清单 >> ├── CurlTools.psm1 # 主模块文件 >> └── en-US/ >> └── about_CurlTools.help.txt # 帮助文件 >> CurlTools/ : 无法将“CurlTools/”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请 确保路径正确,然后再试一次。 所在位置 行:1 字符: 1 + CurlTools/ + ~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (CurlTools/:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException ├── : 无法将“├──”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径 正确,然后再试一次。 所在位置 行:2 字符: 1 + ├── CurlTools.psd1 # 模块清单 + ~~~ + CategoryInfo : ObjectNotFound: (├──:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException ├── : 无法将“├──”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径 正确,然后再试一次。 所在位置 行:3 字符: 1 + ├── CurlTools.psm1 # 主模块文件 + ~~~ + CategoryInfo : ObjectNotFound: (├──:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException └── : 无法将“└──”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径 正确,然后再试一次。 所在位置 行:4 字符: 1 + └── en-US/ + ~~~ + CategoryInfo : ObjectNotFound: (└──:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException └── : 无法将“└──”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径 正确,然后再试一次。 所在位置 行:5 字符: 5 + └── about_CurlTools.help.txt # 帮助文件 + ~~~ + CategoryInfo : ObjectNotFound: (└──:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\Administrator> function Invoke-SecureDownload { >> param(...) >> try { >> # 核心逻辑 >> } >> catch { >> # 添加详细错误信息 >> $errorDetails = @{ >> Url = $Url >> OutputPath = $OutputPath >> Error = $_.Exception.Message >> Timestamp = Get-Date -Format o >> } >> Write-Error (ConvertTo-Json $errorDetails) >> throw >> } >> } >> 所在位置 行:2 字符: 11 + param(...) + ~ 函数参数列表中缺少“)”。 所在位置 行:1 字符: 32 + function Invoke-SecureDownload { + ~ 语句块或类型定义中缺少右“}”。 所在位置 行:2 字符: 14 + param(...) + ~ 表达式或语句中包含意外的标记“)”。 所在位置 行:17 字符: 1 + } + ~ 表达式或语句中包含意外的标记“}”。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingEndParenthesisInFunctionParameterList PS C:\Users\Administrator> # 使用 .NET 方法替代部分 PowerShell cmdlet 提高性能 >> $fileStream = [System.IO.File]::OpenWrite($OutputPath) >> $webClient = [System.Net.WebClient]::new() >> $webClient.DownloadFile($Url, $fileStream) >> $fileStream.Close() >> 使用“1”个参数调用“OpenWrite”时发生异常:“空路径名是非法的。” 所在位置 行:2 字符: 1 + $fileStream = [System.IO.File]::OpenWrite($OutputPath) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ArgumentException 使用“2”个参数调用“DownloadFile”时发生异常:“值不能为 null。 参数名: address” 所在位置 行:4 字符: 1 + $webClient.DownloadFile($Url, $fileStream) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ArgumentNullException 不能对 Null 值表达式调用方法。 所在位置 行:5 字符: 1 + $fileStream.Close() + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [],RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull PS C:\Users\Administrator> function Update-CurlTools { >> param([switch]$Force) >> >> $updateUrl = "https://api.github.com/repos/yourname/curltools/releases/latest" >> $response = Invoke-RestMethod $updateUrl >> $latestVersion = [Version]$response.tag_name >> $currentVersion = [Version](Get-Module CurlTools).Version >> >> if ($latestVersion -gt $currentVersion -or $Force) { >> Write-Host "更新模块到版本 $latestVersion" >> $installScript = Join-Path $env:TEMP "install.ps1" >> Invoke-SecureDownload -Url $response.assets[0].browser_download_url ` >> -OutputPath $installScript >> & $installScript >> } >> } >> PS C:\Users\Administrator> function Update-CurlTools { >> param([switch]$Force) >> >> $updateUrl = "https://api.github.com/repos/yourname/curltools/releases/latest" >> $response = Invoke-RestMethod $updateUrl >> $latestVersion = [Version]$response.tag_name >> $currentVersion = [Version](Get-Module CurlTools).Version >> >> if ($latestVersion -gt $currentVersion -or $Force) { >> Write-Host "更新模块到版本 $latestVersion" >> $installScript = Join-Path $env:TEMP "install.ps1" >> Invoke-SecureDownload -Url $response.assets[0].browser_download_url ` >> -OutputPath $installScript >> & $installScript >> } >> } >> PS C:\Users\Administrator> # 使用 PlatyPS 生成 Markdown 文档 >> Install-Module PlatyPS -Force >> New-MarkdownHelp -Module CurlTools -OutputFolder docs -Force >> 需要使用 NuGet 提供程序来继续操作 PowerShellGet 需要使用 NuGet 提供程序“2.8.5.201”或更高版本来与基于 NuGet 的存储库交互。必须在“C:\Program Files\PackageManagement\ProviderAssemblies”或“C:\Users\Administrator\AppData\Local\PackageManagement\ProviderAssembli es”中提供 NuGet 提供程序。也可以通过运行 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force' 安装 NuGet 提供程序。是否要让 PowerShellGet 立即安装并导入 NuGet 提供程序? [Y] 是(Y) [N] 否(N) [S] 暂停(S) [?] 帮助 (默认值为“Y”):
08-13
那你继续加油吧 你看看我是选Y还是关掉窗口重新开始 还是怎么办?PS C:\Users\Administrator> function Set-CurlVersion { >> [CmdletBinding()] >> param( >> [Parameter(Mandatory=$true)] >> [ValidateSet("custom", "system")] >> [string]$Version >> ) >> >> $platform = Get-Platform >> $currentPath = $env:Path -split [System.IO.Path]::PathSeparator >> >> # 创建系统路径变量 >> $systemPath = if ($platform -eq "Windows") { >> Join-Path -Path $env:SystemRoot -ChildPath "System32" >> } else { >> $null >> } >> >> switch ($Version) { >> "custom" { >> # 添加自定义路径到临时环境变量 >> $newPath = @($script:CurlPath) >> $newPath += $currentPath | Where-Object { >> $_ -ne $systemPath -and >> $_ -ne "/usr/bin" -and >> $_ -ne "/usr/local/bin" >> } >> } >> "system" { >> # 恢复原始环境变量 >> $newPath = $currentPath | Where-Object { $_ -ne $script:CurlPath } >> } >> } >> >> # 更新环境变量 >> $env:Path = $newPath -join [System.IO.Path]::PathSeparator >> Write-Host "已切换到 curl $Version 版本" -ForegroundColor Green >> } >> PS C:\Users\Administrator> # 创建模块目录 >> $moduleDir = "$env:USERPROFILE\Documents\WindowsPowerShell\Modules\CurlTools" >> New-Item -ItemType Directory -Path $moduleDir -Force | Out-Null >> >> # 创建模块文件 >> $modulePath = Join-Path $moduleDir "CurlTools.psm1" >> PS C:\Users\Administrator> $manifestContent = @' >> @{ >> ModuleVersion = '1.0.0' >> RootModule = 'CurlTools.psm1' >> Author = 'Your Name' >> Description = '高级curl工具集模块' >> FunctionsToExport = @( >> 'Get-CurlVersion', >> 'Set-CurlVersion', >> 'Invoke-SecureDownload', >> 'Get-FileHashFromUrl', >> 'Update-CurlToolsModule' >> ) >> CompatiblePSEditions = @('Desktop', 'Core') >> PowerShellVersion = '5.1' >> } >> '@ >> >> Set-Content -Path (Join-Path $moduleDir "CurlTools.psd1") -Value $manifestContent >> PS C:\Users\Administrator> # 完整的模块内容(已修复所有错误) >> $moduleContent = @' >> # CurlTools.psm1 >> # ============== >> # 模块主文件 >> >> # 初始化模块变量 >> $script:Config = $null >> $script:CurlPath = $null >> $script:ConfigDir = $null >> $script:ConfigPath = $null >> >> # 检测操作系统 >> function Get-Platform { >> if ($PSVersionTable.PSEdition -eq "Core") { >> if ($IsWindows) { return "Windows" } >> elseif ($IsLinux) { return "Linux" } >> elseif ($IsMacOS) { return "macOS" } >> } else { >> return "Windows" >> } >> } >> >> # 获取跨平台配置目录 >> function Get-ConfigDir { >> $platform = Get-Platform >> switch ($platform) { >> "Linux" { >> if (-not (Test-Path "$env:HOME/.config")) { >> New-Item -ItemType Directory -Path "$env:HOME/.config" -Force | Out-Null >> } >> return "$env:HOME/.config/curltools" >> } >> "macOS" { >> if (-not (Test-Path "$env:HOME/Library/Application Support")) { >> New-Item -ItemType Directory -Path "$env:HOME/Library/Application Support" -Force | Out-Null >> } >> return "$env:HOME/Library/Application Support/CurlTools" >> } >> default { >> if (-not (Test-Path $env:APPDATA)) { >> New-Item -ItemType Directory -Path $env:APPDATA -Force | Out-Null >> } >> return "$env:APPDATA\CurlTools" >> } >> } >> } >> >> # 获取跨平台curl路径 >> function Get-DefaultCurlPath { >> $platform = Get-Platform >> switch ($platform) { >> "Linux" { return "/usr/bin" } >> "macOS" { return "/usr/local/bin" } >> default { >> # 尝试自动检测Windows上的curl路径 >> $potentialPaths = @( >> "C:\Program Files\curl\bin", >> "C:\curl\bin", >> "$env:USERPROFILE\curl\bin", >> "E:\curl-8.15.0_4-win64-mingw\bin" >> ) >> >> foreach ($path in $potentialPaths) { >> $curlExe = Join-Path $path "curl.exe" >> if (Test-Path $curlExe -PathType Leaf) { >> return $path >> } >> } >> >> # 使用默认路径 >> return "E:\curl-8.15.0_4-win64-mingw\bin" >> } >> } >> } >> >> # 初始化模块配置 >> function Initialize-ModuleConfig { >> $script:ConfigDir = Get-ConfigDir >> >> # 确保配置目录存在 >> if (-not (Test-Path $script:ConfigDir)) { >> New-Item -ItemType Directory -Path $script:ConfigDir -Force | Out-Null >> } >> >> $script:ConfigPath = Join-Path -Path $script:ConfigDir -ChildPath "config.json" >> >> # 加载或创建默认配置 >> if (Test-Path $script:ConfigPath) { >> try { >> $script:Config = Get-Content $script:ConfigPath | ConvertFrom-Json >> } catch { >> Write-Warning "配置加载失败: $_,创建新配置" >> $script:Config = $null >> } >> } >> >> if (-not $script:Config) { >> $script:Config = [PSCustomObject]@{ >> CurlPath = Get-DefaultCurlPath >> LastUpdate = (Get-Date).ToString("o") >> AutoUpdate = $true >> } >> $script:Config | ConvertTo-Json | Set-Content $script:ConfigPath -Force >> } >> >> # 设置模块路径 >> $script:CurlPath = $script:Config.CurlPath >> } >> >> # 保存配置 >> function Save-ModuleConfig { >> $script:Config | ConvertTo-Json | Set-Content $script:ConfigPath -Force >> } >> >> # 在模块导入时自动初始化配置 >> Initialize-ModuleConfig >> >> # 获取文件哈希 >> function Get-FileHashFromUrl { >> <# >> .SYNOPSIS >> 从URL获取文件的哈希值 >> >> .DESCRIPTION >> 下载文件到临时位置并计算其哈希值 >> >> .PARAMETER Url >> 要下载的文件URL >> >> .PARAMETER Algorithm >> 哈希算法 (SHA256, SHA1, MD5等) >> >> .EXAMPLE >> Get-FileHashFromUrl -Url "https://example.com/file.zip" -Algorithm SHA256 >> #> >> param( >> [Parameter(Mandatory=$true)] >> [string]$Url, >> >> [ValidateSet("SHA1", "SHA256", "SHA384", "SHA512", "MD5")] >> [string]$Algorithm = "SHA256" >> ) >> >> $tempFile = [System.IO.Path]::GetTempFileName() >> try { >> Write-Verbose "下载文件以计算哈希: $Url" >> $curlPath = Join-Path $script:CurlPath "curl.exe" >> & $curlPath -L -s -o $tempFile $Url >> >> if (-not (Test-Path $tempFile -PathType Leaf)) { >> throw "文件下载失败" >> } >> >> $hash = (Get-FileHash -Path $tempFile -Algorithm $Algorithm).Hash >> Write-Verbose "$Algorithm 哈希值: $hash" >> return $hash >> } catch { >> Write-Error "获取文件哈希失败: $_" >> return $null >> } finally { >> Remove-Item $tempFile -Force -ErrorAction SilentlyContinue >> } >> } >> >> # 获取curl版本信息 >> function Get-CurlVersion { >> <# >> .SYNOPSIS >> 获取已安装和最新的curl版本信息 >> >> .DESCRIPTION >> 返回包含已安装版本、最新版本和更新命令的对象 >> >> .EXAMPLE >> Get-CurlVersion >> #> >> # 获取已安装版本 >> try { >> $curlPath = Join-Path $script:CurlPath "curl.exe" >> $versionOutput = & $curlPath --version 2>&1 | Out-String >> if (-not ($versionOutput -match 'curl (\d+\.\d+\.\d+)')) { >> throw "无法解析 curl 版本信息" >> } >> $installedVersion = $Matches[1] >> } catch { >> Write-Warning "获取已安装版本失败: $_" >> $installedVersion = "0.0.0" >> } >> >> # 获取最新版本 >> try { >> $latestVersion = $null >> >> # 方案1: 使用官方下载页面解析 >> try { >> $curlPath = Join-Path $script:CurlPath "curl.exe" >> $releasePage = & $curlPath -s -L https://curl.se/download.html >> if ($releasePage -match 'curl (\d+\.\d+\.\d+)</a> is the latest') { >> $latestVersion = $Matches[1] >> } >> } catch { >> Write-Verbose "官方下载页面解析失败: $_" >> } >> >> # 方案2: 使用 GitHub API >> if (-not $latestVersion) { >> try { >> $headers = @{ >> "User-Agent" = "PowerShell-CurlTools" >> "Accept" = "application/vnd.github.v3+json" >> } >> $curlPath = Join-Path $script:CurlPath "curl.exe" >> $releaseInfo = & $curlPath -s -L -H $headers https://api.github.com/repos/curl/curl/releases/latest >> $json = $releaseInfo | ConvertFrom-Json >> $latestVersion = $json.tag_name -replace 'curl-', '' -replace '_', '.' >> } catch { >> Write-Verbose "GitHub API 请求失败: $_" >> } >> } >> >> # 方案3: 从curl.haxx.se获取版本 >> if (-not $latestVersion) { >> try { >> $curlPath = Join-PPath $script:CurlPath "curl.exe" >> $versionPage = & $curlPath -s -L https://curl.haxx.se/info >> if ($versionPage -match 'curl (\d+\.\d+\.\d+)') { >> $latestVersion = $Matches[1] >> } >> } catch { >> Write-Verbose "curl.haxx.se 请求失败: $_" >> } >> } >> >> if (-not $latestVersion) { >> throw "无法获取最新版本" >> } >> } catch { >> Write-Warning "获取最新版本失败: $_" >> $latestVersion = $installedVersion >> } >> >> return [PSCustomObject]@{ >> Installed = $installedVersion >> Latest = $latestVersion >> UpdateCmd = "winget install curl.curl" >> } >> } >> >> # 切换curl版本 >> function Set-CurlVersion { >> <# >> .SYNOPSIS >> 切换使用的curl版本 >> >> .DESCRIPTION >> 在自定义版本和系统版本之间切换 >> >> .PARAMETER Version >> 要切换的版本 (custom 或 system) >> >> .EXAMPLE >> Set-CurlVersion -Version custom >> #> >> [CmdletBinding()] >> param( >> [Parameter(Mandatory=$true)] >> [ValidateSet("custom", "system")] >> [string]$Version >> ) >> >> $platform = Get-Platform >> $currentPath = $env:Path -split [System.IO.Path]::PathSeparator >> >> # 创建系统路径变量 >> $systemPath = if ($platform -eq "Windows") { >> Join-Path -Path $env:SystemRoot -ChildPath "System32" >> } else { >> $null >> } >> >> switch ($Version) { >> "custom" { >> # 添加自定义路径到临时环境变量 >> $newPath = @($script:CurlPath) >> $newPath += $currentPath | Where-Object { >> $_ -ne $systemPath -and >> $_ -ne "/usr/bin" -and >> $_ -ne "/usr/local/bin" >> } >> } >> "system" { >> # 恢复原始环境变量 >> $newPath = $currentPath | Where-Object { $_ -ne $script:CurlPath } >> } >> } >> >> # 更新环境变量 >> $env:Path = $newPath -join [System.IO.Path]::PathSeparator >> Write-Host "已切换到 curl $Version 版本" -ForegroundColor Green >> } >> >> # 安全下载文件 >> function Invoke-SecureDownload { >> <# >> .SYNOPSIS >> 安全下载文件并验证哈希值 >> >> .DESCRIPTION >> 下载文件并验证其哈希值以确保完整性 >> >> .PARAMETER Url >> 要下载的文件URL >> >> .PARAMETER ExpectedHash >> 期望的哈希值(可选) >> >> .PARAMETER Algorithm >> 哈希算法 (默认: SHA256) >> >> .PARAMETER OutputPath >> 输出文件路径 >> >> .PARAMETER AutoVerify >> 自动从源获取哈希值 >> >> .EXAMPLE >> Invoke-SecureDownload -Url "https://example.com/file.zip" -AutoVerify >> #> >> [CmdletBinding()] >> param( >> [Parameter(Mandatory=$true)] >> [string]$Url, >> >> [string]$ExpectedHash, >> >> [ValidateSet("SHA1", "SHA256", "SHA384", "SHA512", "MD5")] >> [string]$Algorithm = "SHA256", >> >> [string]$OutputPath = (Split-Path -Leaf $Url), >> >> [switch]$AutoVerify >> ) >> >> try { >> # 创建下载目录 >> $downloadDir = Split-Path -Path $OutputPath -Parent >> if (-not [string]::IsNullOrEmpty($downloadDir) -and -not (Test-Path $downloadDir)) { >> New-Item -ItemType Directory -Path $downloadDir -Force | Out-Null >> } >> >> # 下载文件 >> Write-Host "下载文件: $Url" -ForegroundColor Cyan >> $curlPath = Join-Path $script:CurlPath "curl.exe" >> & $curlPath -L -o $OutputPath -C - $Url >> >> # 自动获取哈希值(如果需要) >> if ($AutoVerify -or (-not $ExpectedHash)) { >> $ExpectedHash = Get-FileHashFromUrl -Url $Url -Algorithm $Algorithm >> if (-not $ExpectedHash) { >> throw "无法获取远程文件的$Algorithm哈希值" >> } >> Write-Host "自动获取哈希值: $ExpectedHash" -ForegroundColor Yellow >> } >> >> # 验证哈希 >> $actualHash = (Get-FileHash -Path $OutputPath -Algorithm $Algorithm).Hash >> >> if ($actualHash -ne $ExpectedHash) { >> Remove-Item $OutputPath -Force >> throw "文件哈希验证失败! 期望: $ExpectedHash, 实际: $actualHash" >> } >> >> Write-Host "✅ 文件验证成功: $OutputPath" -ForegroundColor Green >> return $OutputPath >> } catch { >> Write-Error "下载失败: $_" >> return $null >> } >> } >> >> # 模块更新函数 >> function Update-CurlToolsModule { >> <# >> .SYNOPSIS >> 更新CurlTools模块到最新版本 >> >> .DESCRIPTION >> 从GitHub仓库下载最新版本的模块文件 >> >> .EXAMPLE >> Update-CurlToolsModule >> #> >> try { >> $updateUrl = "https://raw.githubusercontent.com/yourname/curltools/main/CurlTools.psm1" >> >> # 获取模块路径 >> $moduleDir = if ($PSVersionTable.PSEdition -eq "Core") { >> "$env:USERPROFILE\Documents\PowerShell\Modules\CurlTools" >> } else { >> "$env:USERPROFILE\Documents\WindowsPowerShell\Modules\CurlTools" >> } >> >> $modulePath = Join-Path -Path $moduleDir -ChildPath "CurlTools.psm1" >> >> # 创建备份 >> $backupPath = "$modulePath.bak" >> if (Test-Path $modulePath) { >> Copy-Item -Path $modulePath -Destination $backupPath -Force >> } >> >> # 下载更新 >> Write-Host "下载模块更新..." -ForegroundColor Cyan >> $curlPath = Join-Path $script:CurlPath "curl.exe" >> & $curlPath -L -o $modulePath $updateUrl >> >> # 重新加载模块 >> Remove-Module CurlTools -ErrorAction SilentlyContinue >> Import-Module $modulePath -Force >> >> # 更新配置 >> $script:Config.LastUpdate = (Get-Date).ToString("o") >> Save-ModuleConfig >> >> Write-Host "✅ 模块已成功更新至最新版本" -ForegroundColor Green >> return $true >> } catch { >> # 恢复备份 >> if (Test-Path $backupPath) { >> Copy-Item -Path $backupPath -Destination $modulePath -Force >> Remove-Item $backupPath -Force >> } >> >> Write-Error "模块更新失败: $_" >> return $false >> } >> } >> >> # 导出模块成员 >> Export-ModuleMember -Function Get-CurlVersion, Set-CurlVersion, Invoke-SecureDownload, Get-FileHashFromUrl, Update-CurlToolsModule >> '@ >> >> Set-Content -Path $modulePath -Value $moduleContent -Force >> PS C:\Users\Administrator> # 创建模块目录 >> $moduleDir = "$env:USERPROFILE\Documents\WindowsPowerShell\Modules\CurlTools" >> New-Item -ItemType Directory -Path $moduleDir -Force >> >> # 创建模块清单 >> $manifestContent = @" >> @{ >> ModuleVersion = '1.0.0' >> RootModule = 'CurlTools.psm1' >> Author = 'Your Name' >> Description = '高级curl工具集模块' >> FunctionsToExport = @( >> 'Get-CurlVersion', >> 'Set-CurlVersion', >> 'Invoke-SecureDownload', >> 'Get-FileHashFromUrl', >> 'Update-CurlToolsModule' >> ) >> CompatiblePSEditions = @('Desktop', 'Core') >> PowerShellVersion = '5.1' >> } >> "@ >> Set-Content -Path "$moduleDir\CurlTools.psd1" -Value $manifestContent >> >> # 创建模块文件 >> $modulePath = "$moduleDir\CurlTools.psm1" >> # 使用上面完整的模块内容填充此文件 >> 目录: C:\Users\Administrator\Documents\WindowsPowerShell\Modules Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 2025/8/12 19:05 CurlTools PS C:\Users\Administrator> # 导入模块 >> Import-Module CurlTools -Force >> >> # 获取curl版本信息 >> $versionInfo = Get-CurlVersion >> Write-Host "当前版本: $($versionInfo.Installed)" >> Write-Host "最新版本: $($versionInfo.Latest)" >> >> # 安全下载文件(自动验证哈希) >> $downloadedFile = Invoke-SecureDownload -Url "https://example.com/file.zip" -AutoVerify >> >> # 切换curl版本 >> Set-CurlVersion -Version custom >> >> # 更新模块 >> Update-CurlToolsModule >> 警告: 获取已安装版本失败: 无法将参数绑定到参数“Path”,因为该参数是空值。 警告: 获取最新版本失败: 无法获取最新版本 当前版本: 0.0.0 最新版本: 0.0.0 下载文件: https://example.com/file.zip Invoke-SecureDownload : 下载失败: 无法将参数绑定到参数“Path”,因为该参数是空值。 所在位置 行:10 字符: 19 + ... oadedFile = Invoke-SecureDownload -Url "https://example.com/file.zip" ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-SecureDownload 已切换到 curl custom 版本 下载模块更新... Update-CurlToolsModule : 模块更新失败: 无法将参数绑定到参数“Path”,因为该参数是空值。 所在位置 行:16 字符: 1 + Update-CurlToolsModule + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Update-CurlToolsModule False PS C:\Users\Administrator> # 检查模块是否加载 >> Get-Module -Name CurlTools >> >> # 查看导出的函数 >> (Get-Module CurlTools).ExportedCommands.Keys >> >> # 查看模块路径 >> (Get-Module CurlTools).Path >> ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Script 1.0.0 CurlTools {Get-CurlVersion, Get-FileHashFromUrl, Invoke-SecureDownlo... Get-CurlVersion Get-FileHashFromUrl Invoke-SecureDownload Set-CurlVersion Update-CurlToolsModule C:\Users\Administrator\Documents\WindowsPowerShell\Modules\CurlTools\CurlTools.psm1 PS C:\Users\Administrator> # 设置调试模式 >> Set-PSDebug -Trace 2 >> >> # 运行函数 >> Get-CurlVersion >> >> # 关闭调试 >> Set-PSDebug -Off >> 调试: 5+ >>>> Get-CurlVersion 调试: 165+ function Get-CurlVersion >>>> { 调试: ! CALL function 'Get-CurlVersion' (defined in file 'C:\Users\Administrator\Documents\WindowsPowerShell\Modules\CurlTools\CurlTools.psm1') 调试: 178+ >>>> $curlPath = Join-Path $script:CurlPath "curl.exe" 调试: 185+ >>>> Write-Warning "获取已安装版本失败: $_" 警告: 获取已安装版本失败: 无法将参数绑定到参数“Path”,因为该参数是空值。 调试: 186+ >>>> $installedVersion = "0.0.0" 调试: ! SET $installedVersion = '0.0.0'. 调试: 191+ >>>> $latestVersion = $null 调试: ! SET $latestVersion = ''. 调试: 195+ >>>> $curlPath = Join-Path $script:CurlPath "curl.exe" 调试: 201+ >>>> Write-Verbose "官方下载页面解析失败: $_" 调试: 205+ if ( >>>> -not $latestVersion) { 调试: 207+ >>>> $headers = @{ 调试: ! SET $headers = 'System.Collections.Hashtable'. 调试: 211+ >>>> $curlPath = Join-Path $script:CurlPath "curl.exe" 调试: 216+ >>>> Write-Verbose "GitHub API 请求失败: $_" 调试: 221+ if ( >>>> -not $latestVersion) { 调试: 223+ >>>> $curlPath = Join-PPath $script:CurlPath "curl.exe" 调试: 229+ >>>> Write-Verbose "curl.haxx.se 请求失败: $_" 调试: 233+ if ( >>>> -not $latestVersion) { 调试: 234+ >>>> throw "无法获取最新版本" 调试: 237+ >>>> Write-Warning "获取最新版本失败: $_" 警告: 获取最新版本失败: 无法获取最新版本 调试: 238+ >>>> $latestVersion = $installedVersion 调试: ! SET $latestVersion = '0.0.0'. 调试: 241+ return >>>> [PSCustomObject]@{ 调试: 246+ >>>> } 调试: 8+ >>>> Set-PSDebug -Off Installed Latest UpdateCmd --------- ------ --------- 0.0.0 0.0.0 winget install curl.curl PS C:\Users\Administrator> # 在函数开头添加错误处理 >> function Get-CurlVersion { >> [CmdletBinding()] >> param() >> >> try { >> # 函数主体 >> } >> catch { >> Write-Error "Get-CurlVersion 失败: $_" >> Write-Error "详细信息: $($_.ScriptStackTrace)" >> return $null >> } >> } >> PS C:\Users\Administrator> # 创建自签名证书 >> $cert = New-SelfSignedCertificate -Type CodeSigning -Subject "CN=CurlTools" -KeyUsage DigitalSignature >> >> # 签名模块 >> Set-AuthenticodeSignature -FilePath $modulePath -Certificate $cert >> 目录: C:\Users\Administrator\Documents\WindowsPowerShell\Modules\CurlTools SignerCertificate Status Path ----------------- ------ ---- 96719E43A5BBD9F7A6394A6FE0A4686AEF7667FC UnknownError CurlTools.psm1 PS C:\Users\Administrator> # Tests/Get-CurlVersion.Tests.ps1 >> Describe "Get-CurlVersion" { >> It "返回有效的版本对象" { >> $result = Get-CurlVersion >> $result | Should -Not -Be $null >> $result.Installed | Should -Match '^\d+\.\d+\.\d+$' >> $result.Latest | Should -Match '^\d+\.\d+\.\d+$' >> } >> } >> Describing Get-CurlVersion [-] 返回有效的版本对象 180ms RuntimeException: '-Not' is not a valid Should operator. 在 Get-TestResult、C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\Assertions\Should.ps1 中: 第 42 行 在 Should<End>、C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\Assertions\Should.ps1 中: 第 83 行 在 <ScriptBlock>、<无文件> 中: 第 5 行 在 Invoke-Test、C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\It.ps1 中: 第 253 行 在 ItImpl、C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\It.ps1 中: 第 203 行 在 It、C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\It.ps1 中: 第 117 行 在 <ScriptBlock>、<无文件> 中: 第 3 行 在 Describe、C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\Describe.ps1 中: 第 100 行 在 <ScriptBlock>、<无文件> 中: 第 2 行 PS C:\Users\Administrator> # 安装 PlatyPS >> Install-Module -Name PlatyPS -Force >> >> # 生成帮助文档 >> New-MarkdownHelp -Module CurlTools -OutputFolder docs >> 需要使用 NuGet 提供程序来继续操作 PowerShellGet 需要使用 NuGet 提供程序“2.8.5.201”或更高版本来与基于 NuGet 的存储库交互。必须在“C:\Program Files\PackageManagement\ProviderAssemblies”或“C:\Users\Administrator\AppData\Local\PackageManagement\ProviderAssembli es”中提供 NuGet 提供程序。也可以通过运行 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force' 安装 NuGet 提供程序。是否要让 PowerShellGet 立即安装并导入 NuGet 提供程序? [Y] 是(Y) [N] 否(N) [S] 暂停(S) [?] 帮助 (默认值为“Y”):
08-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值