You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SSIS脚本任务使用ClientSecretCredential连接Azure Key Vault时遇CS0012错误

SSIS脚本任务访问Azure KeyVault时遇CS0012编译错误

代码示例

var kvUri = "myKVURL";

ClientSecretCredential c = new ClientSecretCredential("MyTenant", "MyClientID", "MySecret");

var newUri = new Uri(kvUri);

var client = new SecretClient(new Uri(kvUri), c);

var secret = client.GetSecret("TestSecret").Value.Value;

Dts.Variables["User::KeyValue"].Value = secret;

Dts.TaskResult = (int)ScriptResults.Success;

错误信息

Severity Code Description Project File Line Suppression State
Error CS0012 The type 'Uri' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. ST_89eda56bbb4740abaa476abc76bad3cb C:\My\Dir\AppData\Local\Temp\1\Vsta\SSIS_ST150\Vsta__RsLsgToVEOM75__vUnStuQ\VstahfjzFXySnU__iQAt126nx4Q\ScriptMain.cs 101 Active

已知背景

已将Azure.Identity和Azure.Security.KeyVault.Secrets及其依赖项的NuGet包安装到GAC,并在项目中添加了引用;相同代码在C#控制台应用中可正常运行。

解决建议

  • 指定Uri完整命名空间:将代码中的Uri替换为System.Uri,避免程序集引用歧义,修改后代码:
    var kvUri = "myKVURL";
    
    ClientSecretCredential c = new ClientSecretCredential("MyTenant", "MyClientID", "MySecret");
    
    var client = new SecretClient(new System.Uri(kvUri), c);
    
    var secret = client.GetSecret("TestSecret").Value.Value;
    
    Dts.Variables["User::KeyValue"].Value = secret;
    
    Dts.TaskResult = (int)ScriptResults.Success;
    
  • 匹配.NET框架版本:SSIS脚本任务默认使用较旧的.NET Framework版本(如4.7.2),检查Azure NuGet包版本是否兼容该框架,不兼容则降级到对应支持版本。
  • 手动添加netstandard引用:在脚本任务项目中右键“引用”->“添加引用”,找到并添加netstandard程序集;若找不到,手动编辑项目.csproj文件,添加节点:
    <Reference Include="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
    
  • 放弃GAC部署依赖:SSIS对GAC中的依赖处理存在兼容性问题,直接在脚本任务项目内通过NuGet管理器安装依赖包,确保包版本与项目框架匹配。

内容的提问来源于stack exchange,提问作者lem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 05:50:11