部署C#+ Linq控制台应用程序?

时间:2011-03-30 21:00:29

标签: c# linq deployment console-application

如何编译和部署使用linq的C#/。NET3.5控制台应用程序?

我在Visual Studio 2008(新项目> Visual C#> Windows>控制台应用程序)中编写了一个控制台应用程序“ExcelDriver”,它使用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 RUN AWAY。 (对我来说太迟了。救你自己!)

4 个答案:

答案 0 :(得分:3)

答案 1 :(得分:0)

在同事的机器上更新到.NET 3.5,你应该设置好。

答案 2 :(得分:0)

检查目标计算机是否安装了正确的.Net版本 - 您可以使用smallestdotnet.com网站进行检查

它需要您为

开发的.Net 3.5版本

答案 3 :(得分:0)

之前我遇到过这个问题 - 似乎是System.Core上缺少一个引用

打开.csproj文件并添加类似于以下内容的行:

然后重新启动Visual Studio实例 - 这应该可以正常工作

相关问题