c# - 压缩多个 csv 的 SSIS 脚本任务失败 - 当前上下文中不存在名称 zipfile
问题描述
我正在使用 SSIS 和 ac# 脚本任务。我想在不使用任何 3rd 方应用程序的情况下压缩多个 csv 文件。
这是我的代码:
#region Namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO.Compression;
#endregion
public void Main()
{
{
string startPath = @"\\xxxxxxxxxxxxxxxxxxxxxx\*.csv";
string zipPath = @"\\xxxxxxxxxxxxxxxxxxxxx\result.zip";
ZipFile.CreateFromDirectory(startPath, zipPath);
}
Dts.TaskResult = (int)ScriptResults.Success;
}
但是,ZipFile
被下划线和错误:
当前上下文中不存在名称 zipfile
我基于此 Microsoft 示例: https ://docs.microsoft.com/en-us/dotnet/standard/io/how-to-compress-and-extract-files
上述文章指出:如果您收到构建错误“当前上下文中不存在名称 'ZipFile'”,请将 System.IO.Compression.FileSystem 程序集的引用添加到您的项目中。但是 SSIS 的脚本编辑器中没有 System.IO.Compression.FileSystem 吗?
解决方案
我相信您没有正确设置对 System.IO.Compression 的引用。
仅使用该语句using System.IO.Compression;
不会使 System.IO.Compression 可用,您还必须将正确的 dll 引用到您的项目中。System.IO.Compression 是.Net 附带的.Net 程序集。
- 在解决方案资源管理器中右键单击项目内(或直接在项目上)的引用文件夹。
- 选择添加参考
- 在 Assemblies 或 .NET 选项卡下,查找直到找到 System.IO.Compression.FileSystem.dll。
- 选择它并单击确定。
如果您使用的是核心,则可能需要从 nuget 包中安装它。
推荐阅读
- jquery - 当视频出现在某个容器中时自动播放 youtube 视频
- sql - SQL Server 计算年、季度和月的市场份额
- ruby-on-rails - 无法弄清楚这种方法的错误是什么?
- python - 从一个模块到另一个模块获取动态设置的全局变量
- python - Python 请求 - SAML 登录重定向
- sql-server - 将平面文件导入sql时保留标题名称
- r - 为什么我在模拟泊松随机变量的“for”循环中得到许多 NA
- javascript - 想要对闭包、范围和异步进行一点澄清
- javascript - 尽管有 db.insert 功能,但数据库没有更新
- javascript - 不规则间隔的嵌套 settimeout(更复杂的方式)