如何在 C# 部署中包含文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/988663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:00:36  来源:igfitidea点击:

How can I include files in a C# deployment?

c#installationdeploymentpublish

提问by Adam Davis

I have a DLL I need to deploy with my C# application. It's not currently included in the installation package when I hit "Publish" so how do I include it?

我有一个 DLL,需要与我的 C# 应用程序一起部署。当我点击“发布”时,它当前未包含在安装包中,那么我该如何包含它?

Would the process be any different if I had app.config and other files I wanted to deploy with my application?

如果我有 app.config 和我想与我的应用程序一起部署的其他文件,这个过程会有什么不同吗?

采纳答案by ChrisF

If it's referenced it should be included automatically. I've deployed a couple of apps that require a 3rd party dll and they've published OK.

如果它被引用,它应该被自动包含。我已经部署了几个需要 3rd 方 dll 的应用程序,并且它们已经发布了。

Is the dll referenced correctly in your project? That's the only thing I can think of at the moment that might be the problem, but if it wasn't your code wouldn't compile and/or link anyway.

您的项目中是否正确引用了 dll?这是我目前唯一能想到的可能是问题的事情,但如果不是,您的代码无论如何都不会编译和/或链接。

To get the xls file to deploy all you need to do is add the file to the solution and then set the "Copy to Output Directory" property on the file.

要部署 xls 文件,您只需将文件添加到解决方案中,然后在文件上设置“复制到输出目录”属性。

回答by Andrew Siemer

Can't you add the dll as a resource to your installer project?

您不能将 dll 作为资源添加到您的安装程序项目中吗?

回答by Matthew Ruston

I take it you are using Visual Studio?

我认为您使用的是 Visual Studio?

If your using Visual Studio 2008 (I have no experience with Visual Studio 2005) under the Publishtab in your project properties click on the Application Filesbutton. This will bring up a list of all dependencies assembalies required by your project. If you find that required dll is not being published by the Visual Studio publisher tool by default you can go into here and set the Publish Statusof the offending dll to Include.

如果您在项目属性的“发布”选项卡下使用 Visual Studio 2008(我没有使用 Visual Studio 2005 的经验),请单击“应用程序文件”按钮。这将显示您的项目所需的所有依赖项程序集的列表。如果您发现默认情况下 Visual Studio 发布者工具未发布所需的 dll,您可以进入此处并将违规 dll的发布状态设置为Include

Sometimes in my more complicated projects, depending on the type of dependency, I have to go into this menu and force certain dll's to be included opposed to the default Prerequsitesetting.

有时在我更复杂的项目中,根据依赖的类型,我必须进入这个菜单并强制包含某些 dll,而不是默认的Prerequsite设置。

...but this is all under the assumption you have the assembly properly referenced in the required projects and everything is compiling fine.

...但这一切都假设您在所需的项目中正确引用了程序集,并且一切都可以正常编译。