如何在构建时将其他文件包含到 C# 中的输出目录中? [英] How to include other files to the output directory in C# upon build?

查看:16
本文介绍了如何在构建时将其他文件包含到 C# 中的输出目录中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要一些库文件才能工作.
我的应用程序包含设置和部署.

I have some library files needed for my application to work.
My application has a setup and deployment included.

我已经知道,为了在安装时将库文件添加到应用程序的输出目录中,我只需要在构建之前在 .NET IDE 中引用这些库...唯一的问题是这些库不能被引用...所以我需要能够将这些库复制到我的应用程序的安装目录...目前,我正在手动复制这些库...

I already know that in order for a library file to be added to the output directory of the application when installing, I just have to reference those libraries inside the .NET IDE before building... the only problem is that these libraries can't be referenced... So I need to be able to copy these libraries to the installation directory of my application... At the moment, I am copying these libraries manually...

附录

我也尝试将这些库文件作为现有项目添加到我的项目中,并标记每个库文件的复制到输出目录如果更新 复制他们的属性,但仍然没有得到我想要的解决方案.

I also did try to add these library files as an Existing Item to my project and marked each library files' Copy to Output Directory to Copy if newer on their properties but still not getting the solution I want.

更新 1

感谢你们的帮助,它帮助我解决了我的问题,我设法使你发布的解决方案起作用,除了一个......@Matthew Watson 的帖子......我什至设法找到了一个解决方案,所以我想分享它也和你在一起.

Thanks for you help guys it helped me solve my problem, I managed to make the solutions you posted work except for one... @Matthew Watson's post.. I even managed to find a solution too so I wanted to share it with you also.

这是我所做的:

  1. 我在我的应用程序中打开了设置和部署项目.
  2. 在应用程序文件夹树的右侧,我右键单击..
  3. 然后点击添加...
  4. 然后点击文件
  5. 然后浏览我想添加到安装目录的文件
  6. 然后点击打开.

但出于好奇……我仍在努力使@Matthew Watson 发布的内容发挥作用……希望您能帮助我解决这个问题.提前致谢

But out of curiosity...I am still trying to make what @Matthew Watson posted work...Hope you can help me with this one guys. Thanks in advance

更新 2

我昨天忘记更新这篇文章了,昨天我已经设法让 Matthew Watson 的解决方案起作用了.再次感谢大家的帮助.

I forgot to update this post yesterday, I already manage to make Matthew Watson's solution worked yesterday. Thank you again for all your help guys.

推荐答案

您可以将文件添加到您的项目并选择它们的属性:"Build Action" as "Content""Copy to output directory""Copy Always"Copy if Newer(后者更可取,否则项目每次都完全重建)构建它的时间).

You can add files to your project and select their properties: "Build Action" as "Content" and "Copy to output directory" as "Copy Always" or Copy if Newer (the latter is preferable because otherwise the project rebuilds fully every time you build it).

然后这些文件将被复制到您的输出文件夹.

Then those files will be copied to your output folder.

这比使用后期构建步骤要好,因为 Visual Studio 会知道这些文件是项目的一部分.(这会影响 ClickOnce 应用程序等需要知道要添加到 clickonce 数据的文件.)

This is better than using a post build step because Visual Studio will know that the files are part of the project. (That affects things like ClickOnce applications which need to know what files to add to the clickonce data.)

您还可以更轻松地查看项目中的哪些文件,因为它们将与源代码文件一起列出,而不是隐藏在构建后步骤中.而且源代码管理可以更轻松地与它们一起使用.

You will also be more easily able to see which files are in the project because they will be listed with the source code files rather than hidden in a post-build step. And also Source Control can be used with them more easily.

将内容"文件添加到项目后,您将能够将它们添加到 Visual Studio 2010 安装和部署项目,如下所示:

Once you have added "Content" files to your project, you will be able to add them to a Visual Studio 2010 Setup and Deployment project as follows:

进入您的安装项目并将名为 内容文件" 的项目输出添加到您的 应用程序文件夹" 输出.如果在添加内容文件后右键单击它们,您可以选择输出"并查看它要复制的内容.

Go into your Setup project and add to your "Application Folder" output the Project Output called "Content Files". If you right-click the Content Files after adding them you can select "outputs" and see what it's going to copy.

请注意,Visual Studio 2012 不支持安装和部署项目.

Note that Setup and Deployment projects are NOT supported in Visual Studio 2012.

这篇关于如何在构建时将其他文件包含到 C# 中的输出目录中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆