如何编译和部署使用linq的C#/.NET3.5控制台应用程序?
我在Visual Studio 2008中编写了一个名为“ExcelDriver”的控制台应用程序(新项目 > Visual C# > Windows > 控制台应用程序),它使用Excel.Interop和linq-to-sql。[1]
Build menu > Clean ExcelDriver
Build menu > Build ExcelDriver
这将文件放在文件夹C:\dev\VisualStudio2008\ExcelDriver\ExcelDriver\bin\Release\中。
Directory of C:\dev\VisualStudio2008\ExcelDriver\ExcelDriver\bin\Release
03/30/2011 02:17 PM 12,800 ExcelDriver.exe
03/25/2011 12:14 PM 411 ExcelDriver.exe.config
03/30/2011 02:17 PM 26,112 ExcelDriver.pdb
03/30/2011 01:32 PM 1,093,632 Interop.Excel.dll
03/30/2011 01:32 PM 417,792 Interop.Microsoft.Office.Core.dll
5 File(s) 1,550,747 bytes
C:\dev\VisualStudio2008\ExcelDriver\ExcelDriver\bin\Release>ExcelDriver.exe
当我自己运行这个程序时,它完美地工作。
但是,当我将这5个文件复制到我的同事的电脑上并运行时,它失败了,并抱怨找不到System.Data.Linq。如果我复制整个项目文件夹,也会发生这种情况。
以下是同事电脑上的错误信息:
C:\ExcelDriver>ExcelDriver.exe
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or ass
embly 'System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c
561934e089' or one of its dependencies. The system cannot find the file specifie
d.
File name: 'System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b
77a5c561934e089'
at ExcelDriver.Program.Main(String[] args)
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\M
icrosoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure lo
gging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fus
ion!EnableLog].
C:\ExcelDriver>
很明显当我编译应用程序时,我错过了一些东西。我该怎么做才能将所有的程序集和其他内容放到一个地方,以便我可以部署到其他机器上?
[1] 对我来说,这是一次非常不愉快的经历。从我的痛苦中学习... 如果有人建议你写一个C#应用程序来控制Excel,请走开。(对我来说为时已晚。拯救你自己!)