none
How to set MSBuild to compile multiple times? RRS feed

  • Question

  • In our current product, we have multiple solution files of visual studio and multiple projects in them.

    In those, few of the solutions .sln files may fail some times and if we retry , they will be successful.

    So, we are using devenv.com till date and retrying for 5 times, if it fails on 5th time, we are failing the build job.

    But how to integrate this in MSBuild script. Like, we can use msbuild to build the project but how to set the retry attempts to till 5 and do the build process.

    Is there any .msbuild script you can suggest for this.

    Tuesday, July 9, 2019 9:52 AM

All replies

  • Have you tried MSBuild in StackOverFlow?

    https://stackoverflow.com/questions/tagged/msbuild

    Tuesday, July 9, 2019 10:24 AM
  • Hi ukreddy,

    Thank you for posting here.

    Since this thread is related to MSBuild, I will move it to MSBuild forum to get support.

    The Visual C# forum discusses and asks questions about the C# programming language, IDE, libraries, samples, and tools.

    Best Regards,

    Jack


    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.

    Wednesday, July 10, 2019 8:37 AM
  • Hi ukreddy,

    Sorry for delay in reply.

    For your requirement, we recommend that you could use bat script with msbuild command to implement this function.

    #1 please download build tools here: https://visualstudio.microsoft.com/downloads/

    #2 please refer to the below code:

    @echo off
    cd C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin      //open the path which exe locates
    for /l %%i in (1,1,5) do msbuild.exe D:\C#\test\test.sln       //build project for five times 
    set BUILD_STATUS=%ERRORLEVEL%
    if not %BUILD_STATUS%==0  pause      //check the build status,if failed, pause
    
    next msbuild command
    ...
    
    pause

    Note: please refer more about msbuild command: MSBuild command-line reference

    Any feedback will be expected.

    Best Regards,

    Dylan


    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, July 11, 2019 7:26 AM
  • Is it possible to create another .msbuild file to have a task with retry option along with count.So that when I pass 5 and the sln file to it, it will retry 5 times max if any error and returns as failure if the 5th attempt also fails.

    So that, we can directly integrate it with msbuild plugin of jenkins or any other CI.

    Monday, July 15, 2019 6:09 AM
  • Hi ukreddy,

    Sorry for delay in reply.

    According to your description, did you want to create a srcipt for msbuild which is like .bat and .cmd file?If so, I'm afraid that the answer is negative. And as far as I know, the msbuild is just a tool to build project, there is no related file type for msbuild. 

    And you could add the below command to call the bat file in Jenkins.

    Best Regards,

    Dylan


    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

    Friday, July 26, 2019 7:12 AM
  • Hi friend,

    Any update for this issue? As Dylan suggests, you can call the bat file during build process in Jenkins.

    Also, what's the msbuild script you want? Please check the MSBuild task.

    Maybe you can create a empty project to control the build process by defining a target like this:

    <Target Name="CustomBuild" AfterTargets="build">
        <MSBuild Projects="xxx" Properties="xxx"/>
        <MSBuild Projects="xxx" Properties="xxx"/>
      </Target>

    You can call the msbuild task to build different projects at build time, but it only accept project files as parameter instead of solution file.

    Best Regards

    Lance


    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.

    Monday, August 5, 2019 9:53 AM