none
Post build does not work

    Question

  • I have the following code in post build event:

    xcopy  "$(OutDir)SQLReports" "$(OutDir)Database\SQLServer\SQLReports\*.*" /y /s
    xcopy  "$(OutDir)SQLReports\AutoGenerated" "$(OutDir)Database\SQLServer\SQLReports\AutoGenerated\" /y /s
    xcopy  "$(OutDir)SQLReports\Procedures" "$(OutDir)Database\SQLServer\SQLReports\Procedures\" /y /s
    RD /S /Q  "$(OutDir)\SQLReports"

    The main folder is database and solution looks like this:

    The result \SQLReports folder is missing folders: AutoGenerated and Procedures and only has four single script files.

    Any idea what's wrong?

    Thanks


    Tuesday, March 7, 2017 9:10 PM

All replies

  • Are you attempting to copy from the bin\release directory into the bin\release\Database directory?

    because $(OutDir) = bin\release (or debug).

    If you cleaned your solution these would be empty when you do the build...

    It would be logical to copy from your Solution directory into the target... for all the source files *.* something like:

    XCOPY "$(SolutionDir)SQLReports\*.*" "$(OutDir)Database\SQLServer\SQLReports\" /Y /S

    Tuesday, March 7, 2017 9:35 PM
  • I think it uses \bin\debug.

    <If you cleaned your solution

    Not sure what you mean.

    Tuesday, March 7, 2017 9:38 PM
  • Your syntax was probably wrong: its XCOPY Source\*.* Destination /flags

    Also, have you considered the options for each files such as "Always copy"... look at the properties window.

    Tuesday, March 7, 2017 9:40 PM
  • I am definitely confused how xcopy in post build works.

    If I use this command:

    D:\database\SQLServer>xcopy sqlreports d:\temp\sqlreports\*.* /y /s

     then the whole content of sqlreports folder will be copied into d:\temp. Not sure how to achieve the same in the post build. 

     Thanks
    Tuesday, March 7, 2017 9:48 PM
  • Hi markgoldin,

    Thanks for posting here.

    >>>The result \SQLReports folder is missing folders: AutoGenerated and Procedures and only has four single script files.

    The first thing is that whether SQLReports folder is exists or not after build without the post build event? We should make sure all folders and files are generated under the bin\Debug after build. In this case, we could exclude the error that files not generated. If you can confirm that all the files are generated as expected, I would provide a workaround to instead of post build event. You can add a copy task in your project file to achieve the same result:

        <ItemGroup>
          <MySQLReports Include="$(OutDir)SQLReports\*.*"/>
        </ItemGroup>
    
       <ItemGroup>
         <MyAutoGenerated Include="$(OutDir)SQLReports\AutoGenerated\*.*"/>
       </ItemGroup>
    
        <Target Name="CopyFiles" AfterTargets="Build">
          <Copy
              SourceFiles="@(MySQLReports)"
              DestinationFolder="$(OutDir)Database\SQLServer\SQLReports"
            />
    
         <Copy
             SourceFiles="@(MyAutoGenerated)"
             DestinationFolder="$(OutDir)Database\SQLServer\SQLReports\AutoGenerated"
            />
          
        </Target>

    Update:

    After took long time to investigate the xcopy, I`m work out this question. We need to pay attention to two points:

    1. As Cyrille Précetti mentioned: syntax should: its XCOPY Source\*.* Destination /flags

    2. The Source and Destination path should be full path.

    So the xcopy command line should be:

    xcopy.exe  "$(ProjectDir)$(OutDir)SQLReports\*.*" "$(ProjectDir)$(OutDir)Database\SQLServer\SQLReports" /y /s


    Hope those could help you.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.




    Thursday, March 9, 2017 8:42 AM
  • @markgoldin, I have updated my answer, could you get any useful information from the answer? If not, would you please let me know the latest status of this issue? Thanks.


    MSDN Community Support Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 14, 2017 10:40 AM