部署 C# + Linq 控制台应用程序?
如何编译和部署使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要将 .NET Framework 3.5 部署到目标计算机上。
http://www .microsoft.com/downloads/en/details.aspx?FamilyId=333325fd-ae52-4e35-b531-508d977d32a6&displaylang=en
You need to deploy the .NET Framework 3.5 on to your target machine.
http://www.microsoft.com/downloads/en/details.aspx?FamilyId=333325fd-ae52-4e35-b531-508d977d32a6&displaylang=en
在你同事的机器上更新到 .NET 3.5,你就应该准备好了。
Update to .NET 3.5 on your coworker's machine and you should be set.
检查目标计算机是否安装了正确版本的 .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
我以前遇到过这个问题 - 似乎 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