Problem Executing Batch File in Pre-Build Event

前端 未结 8 1384
攒了一身酷
攒了一身酷 2021-02-20 01:05

I\'m trying to execute a batch file during a pre-build event. I have a new project and have added foo.bat to it. The file contains the following line:

相关标签:
8条回答
  • 2021-02-20 01:13

    The current working directory of the pre-build and post-build events is the output directory specified by the macro $(OutDir), not the project directory.

    The following tags in "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets" specify this:

    <Target
        Name="PreBuildEvent"
        Condition="'$(PreBuildEvent)'!=''"
        DependsOnTargets="$(PreBuildEventDependsOn)">
    
        <Exec WorkingDirectory="$(OutDir)" Command="$(PreBuildEvent)" />
    </Target>
    
    <Target
        Name="PostBuildEvent"
        Condition="'$(PostBuildEvent)' != '' and ('$(RunPostBuildEvent)' != 'OnOutputUpdated' or '$(_AssemblyTimestampBeforeCompile)' != '$(_AssemblyTimestampAfterCompile)')"
        DependsOnTargets="$(PostBuildEventDependsOn)">
    
        <Exec WorkingDirectory="$(OutDir)" Command="$(PostBuildEvent)" />
    </Target>
    
    0 讨论(0)
  • 2021-02-20 01:13

    I solved the problem by creating the .bat file from windows explorer, and then in turn including it into my project, instead of creating in directly in VS 2010.

    0 讨论(0)
  • 2021-02-20 01:14

    The problem I suspect is that there's a SPACE character in your folder path.

    So this command will probably work for c:\development\projectABC\foo.bat but not for c:\development\project ABC\foo.bat

    At least that was the problem for me, there could be other issues, but I suspect this is the most common. The solution: put quotation marks around you batch call:

    "c:\development\project ABC\foo.bat"
    
    0 讨论(0)
  • 2021-02-20 01:22

    1) see error details by View => Output 2) try call "$(SolutionDir)\xx\xx.bat"

    0 讨论(0)
  • 2021-02-20 01:30

    Right click the project --> select properties --> select build event Tab Then Clear the Pre-Build event comment lines.

    0 讨论(0)
  • 2021-02-20 01:31

    I got this working and I figure a picture is worth a thousand words, so here is the full setup in a single screenshot.

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