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

4

如何编译和部署使用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,请走开。(对我来说为时已晚。拯救你自己!)


2
他可能缺少.NET 3.5,你需要使用System.Data.Linq。 - alexn
你的同事缺少 .net 3.5,这是从微软下载的。 - Michael Stum
简单问题,10秒内3次相同的答案 :-) - Snowbear
1
+1 为脚注加一! :-) - Christoffer Lette
4个回答

3

没错。如果您想要让它“独立运行”,可以使用像NSIS(请参见链接)这样的安装程序将所有内容打包在一起,但.NET 3.5是一个相当大的安装包。http://nsis.sourceforge.net/Main_Page - IronicMuffin

0

在你的同事机器上升级到.NET 3.5,然后你就可以开始了。


0

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

它将需要与您开发的相同的 .Net 3.5 版本


0

我之前遇到过这个问题 - 看起来是System.Core上缺少了引用

打开你的.csproj文件并添加类似以下的一行:

然后重新启动您的Visual Studio实例 - 这应该可以解决问题

保罗


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接