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

发布于 2024-10-28 09:33:23 字数 2040 浏览 1 评论 0原文

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

我在 Visual Studio 2008 中编写了一个控制台应用程序“ExcelDriver”(“新建项目”>“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,请逃跑。 (对我来说已经太晚了。救救自己吧!)

How do I compile and deploy a C#/.NET3.5 console application that uses linq?

I wrote a console app "ExcelDriver" in Visual Studio 2008 (New Project > Visual C# > Windows > Console Application) that uses Excel.Interop and linq-to-sql. [1]

Build menu  > Clean ExcelDriver
Build menu > Build ExcelDriver

This puts files in the folder 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

Which works perfectly when I run it.

But when I copy these 5 files to my co-worker's computer and run, it fails and complains that it can't find System.Data.Linq. This also happens if I copy the entire project folder over.

Here's the error message on the coworker machine

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>

Clearly I am missing something when I compile the app. What must I do to get ALL the assemblies and whatnot into one place so I can deploy to other machines?

[1] It's been a very unhappy experience for me. Learn from my pain... If anyone ever suggests to you to write a C# app to control Excel RUN AWAY. (It's too late for me. Save yourself!)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

雨的味道风的声音 2024-11-04 09:33:23

在你同事的机器上更新到 .NET 3.5,你就应该准备好了。

Update to .NET 3.5 on your coworker's machine and you should be set.

末蓝 2024-11-04 09:33:23

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

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

Check the target machine has the correct version of .Net installed - you can use the smallestdotnet.com site to check

It will need the same .Net 3.5 version that you developed for

两相知 2024-11-04 09:33:23

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

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

然后重新启动你的视觉工作室实例 - 这应该可以工作

保罗

I have had this problem before - it seems to be that there is a missing reference on System.Core

open your .csproj file and add a line similar to the following:

then restart your visual studio instance - this should work

paul

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文