【发布时间】:2023-03-05 07:51:01
【问题描述】:
我有一个可以按原样运行的 SSIS 项目,但是当我尝试对其进行编辑时,出现错误:
当前上下文中不存在名称“zipfile”
无需编辑,就可以正常工作。
产生错误的代码:
public void Main()
{
// TODO: Add your code here
string moduleName = Dts.Variables["User::ModuleName"].Value.ToString();
string s = Dts.Variables["User::ZipFileLocation"].Value.ToString().TrimEnd('\\') + "\\" + moduleName + "\\" + moduleName + "_" + DateTime.Now.ToString("ddMMyyyy");
// TODO: Add your code here
string startPath = s;
string zipPath = s + ".zip";
try
{
File.Delete(zipPath);
ZipFile.CreateFromDirectory(startPath, zipPath);
}
catch (Exception e)
{
}
Dts.TaskResult = (int)ScriptResults.Success;
}
我该如何解决这个问题?
【问题讨论】:
-
你可能只引用了 System.IO.Compression,奇怪的是你也需要引用 System.IO.Compression.FileSystem
-
@NilsO 这对我来说是个问题。不知道为什么我们必须为此添加单独的参考,但仍然解决了我的问题。
-
@Chad 这是因为 Zipfile 类位于 System.IO.Compression.FileSystem 程序集中,而它位于 System.IO.Compression 命名空间中。