Visual Studio: Multiple post-build commands?

后端 未结 10 1234
逝去的感伤
逝去的感伤 2020-12-13 16:47

Visual Studio 2008 lets me declare a command and attach it to the post-build event for a project. Like a lot of developers, I use it regularly to xcopy files to the applicat

相关标签:
10条回答
  • 2020-12-13 17:31

    In Visual Studio 2017 you can do this:

    <PostBuildEvent>
        <Command>
            copy $(TargetPath) $(SolutionDIr)\bin1
            copy $(TargetPath) $(SolutionDIr)\bin2
        </Command>
    </PostBuildEvent>
    
    0 讨论(0)
  • 2020-12-13 17:32

    Just prefix "call " to your batch script. So that statements below the Batch script is also executed after returning the call from batch script.

    call Script1.cmd
    call Script2.bat
    
    0 讨论(0)
  • 2020-12-13 17:33

    Separating the commands with & or && or ; does not work in VS2017. Can't belive such simple functionality is not available in VS2017. Visual studio tries to execute the entire text in the post build event window as one string. Only option for me now is to create a batch script which I do not particularly like.

    0 讨论(0)
  • 2020-12-13 17:35

    There is another option: you can separate the commands with &&. E.g.

    copy $(TargetPath) d:\folder1 && copy $(TargetPath) d:\folder2

    This is not exactly the same as separating with newlines: with &&, if the previous command failed, next commant will not run.

    Separating by newlines is easier to read, so you should prefer it. However I know at least one case when && is useful. It is the scenario, when you use property sheets to have different post-build steps on different machines. VS 2008 doesn't allow setting PostBuildStep in property sheets directly, but you can add a user macro with your command and call it from the main project settings. A macro is single line, so you can use && to have multiple commands there.

    0 讨论(0)
提交回复
热议问题