程序有时无法找到合并依赖项

时间:2016-11-11 11:24:41

标签: c# .net pdf itext ilmerge

我有一个小应用程序,它从SharePoint获取一些文件,将它们转换为PDF,然后将所有pdf合并为一个pdf。

程序中最慢的部分是每个文件的转换,因此在测试MergePdfs时,代码如下所示:

var test = true;
CoverPage.Create(ref orderedListPdfFileNames);
var fileInfo = WordFileInformation.Get(ref orderedListPdfFileNames);

if (test)
    { ConsoleMessage("Skipping Conversion Step for faster testing", ConsoleColor.Cyan);}
else { ConvertPdfs(fileInfo); }

try
{
    MergePdfs();
}
catch (Exception ex)
{
    ConsoleMessage($"{ex.Message} \n\n {ex.InnerException} \n\n {ex.Data}", ConsoleColor.Red);
    Console.ReadLine();
}

if (test)
    { ConsoleMessage("Skipping pdf deletion for faster testing", ConsoleColor.Cyan); }
else { DeletePdfs(); }

ConsoleMessage("Done!", ConsoleColor.Green);
Console.ReadLine();

因此代码跳过ConvertPdfs并抓取已经转换的文档并合并它们。

使用ILMerge调用程序集上的itextsharp.dll后,这似乎工作正常。

但是,如果我更改为var test = false;,则会收到错误消息:

  

无法加载文件或程序集'itextsharp,Version = 5.5.10.0,Culture = neutral,PublicKeyToken = 8354ae6d2174ddca'或其中一个依赖项。该系统找不到指定的文件。

很明显它找不到itextsharp.dll(来自nuget page,即itextsharp没有依赖关系)

我不仅将itextsharp.dll合并到我的程序集中,而且当我在跳过ConvertPdfs后调用此库时,它完全正常。

这怎么可能?

如果我要发布更多代码,请告诉我

这是我的发布后批处理文件,它显示了我如何合并依赖项:

CMD
SET parameter=%1
CD %1
ECHO "Copying temporary file..."
COPY PdfConverter.exe temp.exe
ECHO "Copying query file..."
COPY ..\..\camlquery.txt camlquery.txt
ECHO "Merging dependancies..."
"..\..\ILMerge.exe" /out:"PdfConverter.exe" /copyattrs /targetPlatform:"v4" "temp.exe" "Microsoft.SharePoint.Client.Runtime.dll" "Microsoft.SharePoint.Client.dll" "itextsharp.dll" 
ECHO "Removing temporary file..."
DEL temp.exe

0 个答案:

没有答案