问题
Using WinSCP .NETassembly for SFTP support from a C# program. When building my project in Visual Studio, I would like WinSCP.exe
and WinSCPnet.dll
to be copied to the bin
output directory. WinSCPnet.dll
is easy enough - as its added as an assembly reference, just set "Copy Local" to true, and its done.
But what about WinSCP.exe
?
Two things I can think of:
add the file
WinSCP.exe
to the root of the project, and set "Copy To Output Directory" to "Copy always".in project properties Build Events, use post-build event command line to copy the file using command line
copy
command.
Both seem a bit clunky. Is there a better way?
回答1:
The 1. is the correct approach. Except that you want "Copy if newer". I do not see anything "clunky" about it.
Quoting 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).
You actually better install the assembly via NuGet package.
WinSCP NuGet package takes care of these settings itself.
来源:https://stackoverflow.com/questions/43246318/get-exe-file-into-the-build-output-directory