Bundling Microsoft.Office.Interop.Excel.dll as a resource not working
I'm writing a C# program that uses SQLite and Excel. Naturally, I need System.Data.SQLite.dll and Microsoft.Office.Interop.Excel.dll. I want my program to be a single exe, so I want to bundle those DLLs in the assembly. This is my .csproj file:
<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>
Now, this is working fine for System.Data.SQLite.dll - after building the program, my program does not require the DLL to be in the same folder to work. However, the executable does require Microsoft.Office.Interop.Excel.dll to be in the same folder, even though I bundled it just like I b开发者_运维知识库undled System.Data.SQLite.dll.
Now, I know that Microsot.Office.Interop.Excel.dll is inside the assembly, because it increases the file size from 928k to 1952k - an addition of 1024k, which is exactly the size of Microseft.Office.Interop.Excel.dll. So I'm assuming that even though the DLL is inside the assembly, some part of the program still looks for it as a separate file.
So, what am I doing wrong? And how can I fix it?
It's possible to eliminate the need for the Interop assembly. This might be your best bet.
This article on MSDN should help.
In short:
Select the reference for your Interop library. In the Properties window, make sure that the Embed Interop Types property is set to True.
精彩评论