microsoft / azure-pipelines-task-lib

Libraries for writing VSTS and TFS build tasks
https://aka.ms/tfbuild
MIT License
411 stars 270 forks source link

Azure Pipeline task goes to time out then crashes when running Visual Studio 2022 from windows-2022 env #813

Closed xpouyat closed 2 years ago

xpouyat commented 2 years ago

Please check our current Issues to see if someone already reported this https://github.com/Microsoft/azure-pipelines-task-lib/issues

Environment

azure-pipelines-task-lib version:

Issue Description

When running windows-2022 env to run Visual Studio 2022 with Azure DevOps CmdLine@2 task, the task runs fine but does not detect that Visual Studio 2022 finished the work. After 58 min, the task timeout, code raises an exception, and job fails.

I call this task to build a MSI based on a Microsoft Installer Project in the solution, for a .NET 6 application. Microsoft Installer Project is in windows-2022 env.

Issue initially created in https://github.com/actions/virtual-environments/issues/4880. Issue occurs in the ToolFunctions.ps1 file.

Expected behaviour

Task should no timeout and crashes.

Actual behaviour

Task does not detect that Visual Studio finished to execute. After 58 min, an exception is raised

2022-01-12_10h17_48

2022-01-11T21:28:43.9707538Z Updating the Control table...
2022-01-11T21:28:43.9716755Z Updating the ControlEvent table...
2022-01-11T21:28:43.9718617Z Updating the CustomAction table...
2022-01-11T21:28:43.9720316Z Updating the Property table...
2022-01-11T21:28:43.9720854Z
2022-01-11T21:28:43.9722779Z Post-build events finished
2022-01-11T21:28:43.9926453Z ========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========
2022-01-11T22:23:29.7358977Z ##[debug]Re-evaluate condition on job cancellation for step: 'CmdLine'.
2022-01-11T22:23:37.3714210Z Terminate batch job (Y/N)?
2022-01-11T22:23:37.5307904Z Entering debug mode. Use h or ? for help.
2022-01-11T22:23:37.5308679Z
2022-01-11T22:23:37.5630910Z At D:\a_tasks\CmdLine_d9bafed4-0b18-4f58-968d-86655b4d2ce9\2.182.0\ps_modules\VstsTaskSdk\ToolFunctions.ps1:113
2022-01-11T22:23:37.5632056Z char:13
2022-01-11T22:23:37.5632349Z
2022-01-11T22:23:37.5632851Z + if ($originalEncoding) {
2022-01-11T22:23:37.5633211Z
2022-01-11T22:23:37.5633733Z + ~~~~~~~~~~~~~~~~~
2022-01-11T22:23:37.8131767Z ##[debug]Leaving Invoke-VstsTool.
2022-01-11T22:23:37.8475086Z ##[debug]Leaving D:\a_tasks\CmdLine_d9bafed4-0b18-4f58-968d-86655b4d2ce9\2.182.0\cmdline.ps1.
2022-01-11T22:23:37.9330128Z ##[error]The operation was canceled.
2022-01-11T22:23:37.9349411Z ##[debug]System.OperationCanceledException: The operation was canceled.
at System.Threading.CancellationToken.ThrowOperationCanceledException()
at Microsoft.VisualStudio.Services.Agent.Util.ProcessInvoker.ExecuteAsync(String workingDirectory, String fileName, String arguments, IDictionary2 environment, Boolean requireExitCodeZero, Encoding outputEncoding, Boolean killProcessOnCancel, InputQueue1 redirectStandardIn, Boolean inheritConsoleHandler, Boolean keepStandardInOpen, Boolean highPriorityProcess, CancellationToken cancellationToken)
at Microsoft.VisualStudio.Services.Agent.ProcessInvokerWrapper.ExecuteAsync(String workingDirectory, String fileName, String arguments, IDictionary2 environment, Boolean requireExitCodeZero, Encoding outputEncoding, Boolean killProcessOnCancel, InputQueue1 redirectStandardIn, Boolean inheritConsoleHandler, Boolean keepStandardInOpen, Boolean highPriorityProcess, CancellationToken cancellationToken)
at Microsoft.VisualStudio.Services.Agent.Worker.Handlers.DefaultStepHost.ExecuteAsync(String workingDirectory, String fileName, String arguments, IDictionary`2 environment, Boolean requireExitCodeZero, Encoding outputEncoding, Boolean killProcessOnCancel, Boolean inheritConsoleHandler, CancellationToken cancellationToken)
at Microsoft.VisualStudio.Services.Agent.Worker.Handlers.PowerShell3Handler.RunAsync()
at Microsoft.VisualStudio.Services.Agent.Worker.TaskRunner.RunAsync()
at Microsoft.VisualStudio.Services.Agent.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken jobCancellationToken)
2022-01-11T22:23:37.9359065Z ##[section]Finishing: CmdLine

Pipeline YML

# .NET Desktop

# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net

trigger:
- master

pool:
  vmImage: 'windows-2022'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '**\AMSExplorer\AMSExplorer.csproj'

- task: CmdLine@2
  inputs:
    script: '"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\devenv.com" AMSExplorer.sln /Rebuild Release'
    workingDirectory: '$(System.DefaultWorkingDirectory)'

- task: PublishPipelineArtifact@1
  inputs:
    targetPath: '$(System.DefaultWorkingDirectory)\Setup\Release'
    artifact: 'Setup'
    publishLocation: 'pipeline'

Steps to reproduce

  1. Use Azure DevOps and setup a pipeline to build an app
  2. YML for the pipeline and simple sample Visual Studio Solution is provided in this zip : project-with-yml.zip
  3. Run the pipeline

Logs

6_CmdLine.zip

jessehouwing commented 2 years ago

Try adding my agent screenshot task, my guess is that visual studio has a modal dialog preventing it from closing.

https://marketplace.visualstudio.com/items?itemName=jessehouwing.agent-screenshot

On Tue, 18 Jan 2022, 14:11 Xavier Pouyat, @.***> wrote:

Please check our current Issues to see if someone already reported this https://github.com/Microsoft/azure-pipelines-task-lib/issues Environment

azure-pipelines-task-lib version: Issue Description

When running windows-2022 env to run Visual Studio 2022 with Azure DevOps @.*** task, the task runs fine but does not detect that Visual Studio 2022 finished the work. After 58 min, the task timeout, code raises an exception, and job fails.

I call this task to build a MSI based on a Microsoft Installer Project in the solution, for a .NET 6 application. Microsoft Installer Project is in windows-2022 env.

Issue initially created in actions/virtual-environments#4880 https://github.com/actions/virtual-environments/issues/4880. Issue occurs in the ToolFunctions.ps1 https://github.com/microsoft/azure-pipelines-task-lib/blob/b901effb8eaf6455b3044d57b0e0b4121aa7aa30/powershell/VstsTaskSdk/ToolFunctions.ps1#L112 file. Expected behaviour

Task should no timeout and crashes. Actual behaviour

Task does not detect that Visual Studio finished to execute. After 58 min, an exception is raised

[image: 2022-01-12_10h17_48] https://user-images.githubusercontent.com/8104205/149942190-e71a855b-bf8e-4245-a929-7e49df0967a0.png

2022-01-11T21:28:43.9707538Z Updating the Control table... 2022-01-11T21:28:43.9716755Z Updating the ControlEvent table... 2022-01-11T21:28:43.9718617Z Updating the CustomAction table... 2022-01-11T21:28:43.9720316Z Updating the Property table... 2022-01-11T21:28:43.9720854Z 2022-01-11T21:28:43.9722779Z Post-build events finished 2022-01-11T21:28:43.9926453Z ========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ========== 2022-01-11T22:23:29.7358977Z ##[debug]Re-evaluate condition on job cancellation for step: 'CmdLine'. 2022-01-11T22:23:37.3714210Z Terminate batch job (Y/N)? 2022-01-11T22:23:37.5307904Z Entering debug mode. Use h or ? for help. 2022-01-11T22:23:37.5308679Z 2022-01-11T22:23:37.5630910Z At D:\a_tasks\CmdLine_d9bafed4-0b18-4f58-968d-86655b4d2ce9\2.182.0\ps_modules\VstsTaskSdk\ToolFunctions.ps1:113 2022-01-11T22:23:37.5632056Z char:13 2022-01-11T22:23:37.5632349Z 2022-01-11T22:23:37.5632851Z + if ($originalEncoding) { 2022-01-11T22:23:37.5633211Z 2022-01-11T22:23:37.5633733Z + ~~~~~ 2022-01-11T22:23:37.8131767Z ##[debug]Leaving Invoke-VstsTool. 2022-01-11T22:23:37.8475086Z ##[debug]Leaving D:\a_tasks\CmdLine_d9bafed4-0b18-4f58-968d-86655b4d2ce9\2.182.0\cmdline.ps1. 2022-01-11T22:23:37.9330128Z ##[error]The operation was canceled. 2022-01-11T22:23:37.9349411Z ##[debug]System.OperationCanceledException: The operation was canceled. at System.Threading.CancellationToken.ThrowOperationCanceledException() at Microsoft.VisualStudio.Services.Agent.Util.ProcessInvoker.ExecuteAsync(String workingDirectory, String fileName, String arguments, IDictionary2 environment, Boolean requireExitCodeZero, Encoding outputEncoding, Boolean killProcessOnCancel, InputQueue1 redirectStandardIn, Boolean inheritConsoleHandler, Boolean keepStandardInOpen, Boolean highPriorityProcess, CancellationToken cancellationToken) at Microsoft.VisualStudio.Services.Agent.ProcessInvokerWrapper.ExecuteAsync(String workingDirectory, String fileName, String arguments, IDictionary2 environment, Boolean requireExitCodeZero, Encoding outputEncoding, Boolean killProcessOnCancel, InputQueue1 redirectStandardIn, Boolean inheritConsoleHandler, Boolean keepStandardInOpen, Boolean highPriorityProcess, CancellationToken cancellationToken) at Microsoft.VisualStudio.Services.Agent.Worker.Handlers.DefaultStepHost.ExecuteAsync(String workingDirectory, String fileName, String arguments, IDictionary`2 environment, Boolean requireExitCodeZero, Encoding outputEncoding, Boolean killProcessOnCancel, Boolean inheritConsoleHandler, CancellationToken cancellationToken) at Microsoft.VisualStudio.Services.Agent.Worker.Handlers.PowerShell3Handler.RunAsync() at Microsoft.VisualStudio.Services.Agent.Worker.TaskRunner.RunAsync() at Microsoft.VisualStudio.Services.Agent.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken jobCancellationToken) 2022-01-11T22:23:37.9359065Z ##[section]Finishing: CmdLine

Pipeline YML

.NET Desktop

Build and run tests for .NET Desktop or Windows classic desktop solutions.

Add steps that publish symbols, save build artifacts, and more:

https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net

trigger:

  • master

pool: vmImage: 'windows-2022'

variables: solution: '*/.sln' buildPlatform: 'Any CPU' buildConfiguration: 'Release'

steps:

  • task: @.***

  • task: @.* inputs: restoreSolution: '\AMSExplorer\AMSExplorer.csproj'

  • task: @.*** inputs: script: '"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\devenv.com" AMSExplorer.sln /Rebuild Release' workingDirectory: '$(System.DefaultWorkingDirectory)'

  • task: @.*** inputs: targetPath: '$(System.DefaultWorkingDirectory)\Setup\Release' artifact: 'Setup' publishLocation: 'pipeline'

Steps to reproduce

  1. Use Azure DevOps and setup a pipeline to build an app
  2. YML for the pipeline and simple sample Visual Studio Solution is provided in this zip : project-with-yml.zip https://github.com/microsoft/azure-pipelines-task-lib/files/7889216/project-with-yml.zip
  3. Run the pipeline

Logs

6_CmdLine.zip https://github.com/microsoft/azure-pipelines-task-lib/files/7889227/6_CmdLine.zip

— Reply to this email directly, view it on GitHub https://github.com/microsoft/azure-pipelines-task-lib/issues/813, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA724S4HTBPKBQVWQS5RGQDUWVRHHANCNFSM5MHEHVMQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

jessehouwing commented 2 years ago

That's one of the dangers of running devenv.com to build the project instead of relying on msbuild.

xpouyat commented 2 years ago

I modified the YML and this is the screenshot I get. Please note that I manually canceled the job when the Visual Studio process seems completed (I did not wait for the task to timeout naturally after 58 min. I will post another new screenshot later today when the task timesout) 8_screenshot

xpouyat commented 2 years ago

Screenshot is the same if I wait for the task to timeout naturally.

jessehouwing commented 2 years ago

Looks like visual studio is properly killed prior to the screenshot being taken, that's unfortunate.

AndreyIvanov42 commented 2 years ago

I've read the history of the other issues you mention and can definitely tell that the issue is not related to this repository. Thanks!

mwmorrisCCorp commented 1 year ago

I have this same exact issue. Has a solution been found? I am incorporating MSI builds into on-prem Azure DevOps build. All online blogs indicate you have to use 'devenv.com' to get something to remotely work.....but the task hangs until the timeout fires and the build step indicates failure even though the MSI is actually built. @xpouyat @jessehouwing @AndreyIvanov42

Here is the reference for the MSI step in the build; https://stackoverflow.com/questions/54630699/vsts-build-is-not-generating-msi-file-using-vdproj/68646694#68646694

jessehouwing commented 1 year ago

The best solution is to migrate to Wix. The visual studio installer projects are just not and have never really been stable in a CI/CD environment.

mwmorrisCCorp commented 1 year ago

Thanks for the reply.