问题
I have been manually copying dlls, exe, etc. from a "C# Command Line" project to a UNC server share to be executed by a scheduled task.
Does anyone have a suggestion how I can turn this into a simple operation in Visual Studio?
Here is what I have tried:
Publish wizard. It asks how users will install the application, which is totally irrelevant to my situation. I just want to put it out on a server share.
Project Properties -> Publish. This seems pretty much to be the same as the publish wizard.
Batch file or PowerShell script included in project. I don't see an easy way to launch it from within Visual Studio.
回答1:
If you just need to copy the exe/dlls from output folder you can have a Post-build event in your Visual studio and specify XCOPY command to copy output of the folder to your server shared folder like:
XCOPY $(OutDir) \\Server\folder
If you do not want to copy on each build then you have to manually copy the files in the server. You can write a batch file and execute that once you are done. I am not aware of any direct method in visual studio that does it for you.
回答2:
Use the Post-build event to xcopy the files. You'll want to make it conditional so you'll only copy when the Release build is selected. Make it look like this:
if not "$(OutDir)" == "bin\Release\" goto skip
xcopy /d /y "$(TargetDir)*.*" \\foo\bar
:skip
回答3:
I do not want to deploy on every build event, and I tend to always build in Debug mode, so Hans' advice on putting conditions into the build event doesn't fit my situation.
Why do I always use Debug mode? My apps are small and for internal use. Performance is typically bound by external constraints, not C# code performance or memory size. If it wasn't a drop-down menu that remembers its state, I would be more comfortable using it. When I do use it, I forget, and then I'm compiling in release mode all the time and wondering why the .exe and .dlls aren't getting updated in the Debug folder.
My imperfect solution is to include batch files within my project, and manually start a command shell window to run them. This isn't the solution I wanted, but it is the best compromise for me.
来源:https://stackoverflow.com/questions/20524619/how-to-copy-or-deploy-c-sharp-command-line-project-from-visual-studio