C# 在项目中添加一个 EXE 文件,这样它就会像 DLL 一样被复制到 Bin/Debug 文件夹中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18728406/
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-10 13:02:04  来源:igfitidea点击:

Add an EXE file to a project, so that it will be copied to the Bin/Debug folder just like a DLL?

c#visual-studio-2010tfs

提问by John

I need my C# project to launch another EXE program during execution. This executable needs to be placed in the same folder as the C# program is placed on building the solution, for example, the debug folder -- just like DLL file references -- so that when my team members check the project out from TFS, and debug, the EXE is found when my C# code tries to call it.

我需要我的 C# 项目在执行期间启动另一个 EXE 程序。这个可执行文件需要与 C# 程序在构建解决方案时放置在同一个文件夹中,例如,调试文件夹——就像 DLL 文件引用一样——这样当我的团队成员从 TFS 检出项目时,以及调试时,当我的 C# 代码尝试调用它时会找到 EXE。

However, the EXE is not a reference per se, and so it cannot be added as a reference, even though I want it to be copied around in the same manner as a reference.

但是,EXE 本身不是参考,因此不能将其添加为参考,即使我希望以与参考相同的方式复制它。

Is there a reasonable solution for this problem?

这个问题有合理的解决方案吗?

Thanks in advance.

提前致谢。

采纳答案by Habib

You can go the properties of the file, and under Copy to output Directory select, copy if newer

您可以转到文件的属性,然后在复制到输出目录下选择, copy if newer

enter image description here

在此处输入图片说明

回答by Darin Dimitrov

You could add the executable as item to your C# project and in its properties set its Copy to Output Directoryproperty to Copy always. This way the executable will be copied to the output folder (bin\Debugor bin\Release) everytime you compile your project.

您可以将可执行文件作为项目添加到 C# 项目中,并在其属性中将其属性设置Copy to Output DirectoryCopy always. 这样,每次编译项目时,可执行文件都会被复制到输出文件夹(bin\Debugbin\Release)。

回答by Habib

Package the .exewith the setup of your program.

.exe与您的程序设置一起打包。

Just add it to the Applications Folder. Its the same as it being in the bin/Debugfolder.

只需将其添加到Applications Folder. 它与bin/Debug文件夹中的相同。

回答by TheHube

Create a batch file that is performing the copy action after the build. It is possible to do other stuff pre-build and post build. See http://msdn.microsoft.com/en-us/library/ke5z92ks.aspx

创建一个在构建后执行复制操作的批处理文件。可以在构建前和构建后做其他事情。请参阅http://msdn.microsoft.com/en-us/library/ke5z92ks.aspx