我正在编写一个使用SQLite和Excel的C#程序。当然,我需要System。数据SQLite.dll和Microsoft。办公室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来说运行良好。数据SQLite.dll-在构建程序后,我的程序不需要dll在同一文件夹中即可工作。但是,可执行文件确实需要Microsoft。办公室Interop。Excel.dll在同一个文件夹中,尽管我像捆绑System一样捆绑了它。数据SQLite.dll.
现在,我知道了Microsot。办公室Interop。Excel.dll在程序集中,因为它将文件大小从928k增加到1952k,增加了1024k,这正是Microseft的大小。办公室Interop。Excel.dll。所以我假设即使dll在程序集中,程序的某些部分仍然会将其作为一个单独的文件来查找。
那么,我做错了什么?我该怎么修?
可以消除对互操作程序集的需要。这可能是你最好的选择。
MSDN上的这篇文章应该会有所帮助。
简而言之:
选择Interop库的参考。在"属性"窗口中,确保"嵌入互操作类型"属性设置为True。