【发布时间】:2011-06-21 13:16:34
【问题描述】:
我正在编写一个使用 SQLite 和 Excel 的 C# 程序。当然,我需要 System.Data.SQLite.dll 和 Microsoft.Office.Interop.Excel.dll。我希望我的程序是单个 exe,所以我想将这些 DLL 捆绑在程序集中。这是我的 .csproj 文件:
<Project DefaultTargets="Compile"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<appname>AppName</appname>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<CSFile Include="*.cs"/>
</ItemGroup>
<ItemGroup>
<DLLResource Include="System.Data.SQLite.dll"/>
<DLLResource Include="Microsoft.Office.Interop.Excel.dll"/>
<DLLReference Include="System.Data.SQLite.dll"/>
<DLLReference Include="Microsoft.Office.Interop.Excel.dll"/>
</ItemGroup>
<ItemGroup>
<BundledResource Include="std_db_build.xml"/>
<BundledResource Include="std_report_make.xml"/>
</ItemGroup>
<Target Name="Compile">
<CSC
Sources="@(CSFile)"
Resources="@(DLLResource);@(BundledResource)"
References="@(DLLReference)"
OutputAssembly="$(appname).exe">
</CSC>
</Target>
<Target Name="Run">
<Exec Command="start $(COMSPEC) /k "$(PathTo)$(appname).exe & pause>null & exit"" />
</Target>
<Target Name="Clean">
<Delete Files="$(appname).exe"/>
</Target>
</Project>
现在,这对 System.Data.SQLite.dll 工作正常 - 构建程序后,我的程序不需要 DLL 位于同一文件夹中即可工作。但是,可执行文件确实要求 Microsoft.Office.Interop.Excel.dll 位于同一个文件夹中,即使我将其捆绑为就像捆绑 System.Data.SQLite.dll 一样。
现在,我知道 Microsot.Office.Interop.Excel.dll 在程序集中,因为它将文件大小从 928k 增加到 1952k - 增加了 1024k,这正是 Microseft.Office.Interop 的大小。 Excel.dll。所以我假设即使 DLL 在程序集中,程序的某些部分仍将其作为单独的文件查找。
那么,我做错了什么?我该如何解决?
【问题讨论】: