如何以包括其他文件时建立在C#中的输出目录?文件、目录

2023-09-03 06:47:53 作者:夏天烟火莪的尸体

我需要一些库文件为我的应用程序工作。 我的应用程序有一个安装和部署包括在内。

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沃森的岗位工作的解决方案。我甚至设法找到解决的办法也所以我想分享你还。

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.

下面有什么,我所做的:

Heres what I did:

1. I opened the setup and deployment project in my application.  
2. Under the Application Folder Tree, on it's right side, I right clicked..  
3. then clicked Add..  
4. then clicked File  
5. and then browsed for the files I wanted to add to the installation directory  
6. and click open.  

但出于好奇......我现在还在做什么呢@Matthew沃森投递工作...希望你可以帮我这个人。在此先感谢

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

我忘了昨天更新这个帖子,我已经设法使马修·沃森的解决方案,昨天的工作。再次感谢各位的帮助球员。

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.

推荐答案

您可以将文件添加到您的项目,并选择其属性:生成操作内容复制到输出目录一直拷贝复制如果较新(后者是preferable,否则该项目每次你盖了一次全面重建)。

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.)

您也更容易能看到哪些文件是在项目中,因为他们将列出与源$ C ​​$ C文件,而不是藏在生成后步骤。而且还源控制,可以与他们更容易使用。

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.