Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-26948

Workflow compatibility for MsBuildBuilder

    Details

    • Similar Issues:

      Description

      msbuild-plugin should implement SimpleBuildStep to allow tighter workflow integration.

        Attachments

          Issue Links

            Activity

            Hide
            kon Kalle Niemitalo added a comment - - edited

            For later versions of MSBuild that come with Visual Studio, I think the best way is to run vswhere (which could be a custom tool) and derive the path of MSBuild.exe from its output.

            I put this in one stage:

                        environment {
                            VSWHERE_DIR = tool(type: 'com.cloudbees.jenkins.plugins.customtools.CustomTool', name: 'vswhere')
                        }
            

            Then this as the first step:

                            script {
                                // The @ sign prevents CMD.EXE from echoing the command and
                                // thus messing up the JSON output.
                                def VisualStudioInstances = readJSON(
                                    text: bat(
                                        script: '@"%VSWHERE_DIR%\\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools Microsoft.VisualStudio.Product.Professional -requires Microsoft.Component.MSBuild -format json',
                                        returnStdout: true))
            
                                def VisualStudioInstallationPath = VisualStudioInstances[0].installationPath
                                echo "Using Visual Studio from ${VisualStudioInstallationPath}"
                                env.VSDEVCMD_BAT = VisualStudioInstallationPath + '\\Common7\\Tools\\vsdevcmd.bat'
                            }
            

            And the step to run MSBuild:

                            bat 'CALL "%VSDEVCMD_BAT%" && MSBuild.exe /property:Platform="Any CPU",Configuration="Release" /target:Restore;Build "SOLUTION.sln"'
            

            The projects in this solution use PackageReference rather than packages.config, so Jenkinsfile can use /target:Restore instead of locating and running nuget.exe.

            This seems to work but a few things could be improved:

            • Error handling, if no matching version of Visual Studio has been installed.
            • Also recognize Enterprise, Express, and Community editions. Perhaps it's best to say -products *.
            • Perhaps move to a sharable pipeline library.
            Show
            kon Kalle Niemitalo added a comment - - edited For later versions of MSBuild that come with Visual Studio, I think the best way is to run vswhere (which could be a custom tool) and derive the path of MSBuild.exe from its output. I put this in one stage: environment { VSWHERE_DIR = tool(type: 'com.cloudbees.jenkins.plugins.customtools.CustomTool' , name: 'vswhere' ) } Then this as the first step: script { // The @ sign prevents CMD.EXE from echoing the command and // thus messing up the JSON output. def VisualStudioInstances = readJSON( text: bat( script: '@ "%VSWHERE_DIR%\\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools Microsoft.VisualStudio.Product.Professional -requires Microsoft.Component.MSBuild -format json' , returnStdout: true )) def VisualStudioInstallationPath = VisualStudioInstances[0].installationPath echo "Using Visual Studio from ${VisualStudioInstallationPath}" env.VSDEVCMD_BAT = VisualStudioInstallationPath + '\\Common7\\Tools\\vsdevcmd.bat' } And the step to run MSBuild: bat 'CALL "%VSDEVCMD_BAT%" && MSBuild.exe /property:Platform= "Any CPU" ,Configuration= "Release" /target:Restore;Build "SOLUTION.sln" ' The projects in this solution use PackageReference rather than packages.config , so Jenkinsfile can use /target:Restore instead of locating and running nuget.exe . This seems to work but a few things could be improved: Error handling, if no matching version of Visual Studio has been installed. Also recognize Enterprise, Express, and Community editions. Perhaps it's best to say -products * . Perhaps move to a sharable pipeline library.
            Hide
            mdkf Michael Fowler added a comment - - edited

            I have a PR open here: https://github.com/jenkinsci/msbuild-plugin/pull/36 to add pipeline support.

            Show
            mdkf Michael Fowler added a comment - - edited I have a PR open here: https://github.com/jenkinsci/msbuild-plugin/pull/36  to add pipeline support.
            Hide
            antgel Antony Gelberg added a comment -

            Wrong link?

            Show
            antgel Antony Gelberg added a comment - Wrong link?
            Hide
            amidar Amit Dar added a comment -

            I see the last entry in this log is from last year.

            Is someone still working on this issue? this is a major feature we are looking in our company...

            Show
            amidar Amit Dar added a comment - I see the last entry in this log is from last year. Is someone still working on this issue? this is a major feature we are looking in our company...
            Hide
            jglick Jesse Glick added a comment -

            this is a major feature we are looking [for]

            For what it is worth, see my discussion.

            Show
            jglick Jesse Glick added a comment - this is a major feature we are looking [for] For what it is worth, see my discussion .

              People

              • Assignee:
                mdkf Michael Fowler
                Reporter:
                nharniman Nigel Harniman
              • Votes:
                36 Vote for this issue
                Watchers:
                41 Start watching this issue

                Dates

                • Created:
                  Updated: