提问人:One Developer 提问时间:11/18/2023 最后编辑:One Developer 更新时间:11/23/2023 访问量:168
Azure DevOps 管道:无法加载文件或程序集“Microsoft.Bcl.AsyncInterfaces,版本 = 7.0.0.0”
Azure DevOps Pipeline: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=7.0.0.0'
问:
我正在使用一个Azure DevOps管道,该管道旨在执行存储在存储库中的PowerShell脚本。此脚本使用“rhubarb-geek-nz.NpgsqlConnection“模块与 Postgres SQL 数据库进行交互。
虽然该脚本在我的本地计算机上完美运行,但在尝试从 Azure Pipeline 执行它时遇到错误。
trigger:
- none
stages:
- stage: Dev
jobs:
- job: "Setup"
pool:
vmImage: 'ubuntu-latest'#tried with 'windows-latest' and 'mac13'
steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: 'Write-Host "PowerShell $(pwsh --version)"'
- task: PowerShell@2
inputs:
targetType: 'filePath'
filePath: './setup.ps1'
arguments: '-Env "dev"'
更新 (11-20):setup.ps1
function Install-AdditionalModules {
Write-Output "Installing the required modules"
# This module is required to communicate with Postgres
Install-Module -Name rhubarb-geek-nz.NpgsqlConnection -Confirm:$False -Force -ErrorAction SilentlyContinue
}
# Install Additional Modules
Install-AdditionalModules
function Close-DatabaseConnection {
[CmdletBinding()]
param(
[Npgsql.NpgsqlConnection]$connection
)
try
{
$connection.Dispose()
}
catch {
Write-Host "The connection to the Database could not be terminated: $($_.Exception.InnerException.Message)"
}
}
function Open-DatabaseConnection {
[CmdletBinding()]
param(
[PSCustomObject]$commonConfig
)
$connection = New-NpgsqlConnection -ConnectionString $commonConfig.connectionstring
try
{
$connection.Open()
}
catch {
Write-Host "The connection to the Database could not be established: $($_.Exception.InnerException.Message)"
}
return $connection
}
function Add-Record {
[CmdletBinding()]
param(
[Npgsql.NpgsqlConnection]$connection,
[string]$commandText
)
$command = $connection.CreateCommand()
$command.CommandText = $commandText
try
{
$command.ExecuteNonQuery() | Out-Null
}
catch {
Write-Host "The record could not be added to the Database: $($_.Exception.InnerException.Message)"
}
}
$connection = Open-DatabaseConnection -commonConfig $config.commonConfig
Add-Record -connection $connection -commandText "Insert into ..."
更新#2:我尝试添加,但没有解决问题
Add-Type -Path "Assemblies\Microsoft.Bcl.AsyncInterfaces.dll"
答:
0赞
One Developer
11/23/2023
#1
我成功地开发了一个 Python 脚本来满足我的要求。下面是代码片段:
import psycopg2
def add_record(connection, command_text):
try:
with connection.cursor() as cur:
cur.execute(command_text)
connection.commit()
except Exception as e:
print(f'An error occurred while adding the record to the Tenant Database: {str(e)}')
虽然 PowerShell 提供跨平台兼容性,但它确实有某些限制。在这种情况下,Python 被证明更有效。
评论
Setup -TenantEvn.....