获取exe文件到构建输出目录

Get exe file into the build output directory

使用 WinSCP .NETassembly 从 C# 程序获得 SFTP 支持。在 Visual Studio 中构建我的项目时,我希望将 WinSCP.exeWinSCPnet.dll 复制到 bin 输出目录。 WinSCPnet.dll 很简单——因为它是作为程序集引用添加的,只需将 "Copy Local" 设置为 true,即可完成。

但是 WinSCP.exe 呢?

我能想到的两件事:

  1. 将文件WinSCP.exe添加到项目的根目录,并将"Copy To Output Directory"设置为"Copy always".

  2. 在项目属性Build Events中,使用post-build event命令行复制文件使用命令行copy命令.

两者看起来都有些笨拙。有没有更好的办法?

1.是正确的做法。除了你想要 "Copy if newer"。我没有看到任何关于它的东西 "clunky"。


引用 WinSCP documentation for using the assembly in Visual Studio:

You may want to add winscp.exe to your Visual Studio project, to have it copied to the Output path automatically (by setting file property Copy to Output Directory to Copy if newer). The Build Action should be automatically set to Content, what means that the file will be included when deploying your application (e.g. an ASP.NET web application or Azure WebJob application).


你其实更好install the assembly via NuGet package.

WinSCP NuGet package 自行处理这些设置。