gpt4 book ai didi

c# - 在 Azure DevOps 中运行时,.Net/VS 测试运行器失败

转载 作者:行者123 更新时间:2023-12-04 04:24:00 24 4
gpt4 key购买 nike

我正在运行针对 .Net Framework 4.6.2 的 C# 单元测试。

事情在本地运行良好,它也可以从安装在构建代理上的 VS2019 构建和运行所有测试。

但是,在 Azure DevOps 中运行构建时,使用托管或自托管代理,即使所有测试都成功,测试步骤也会失败。

运行 vstest.console.exe从命令行手动,在构建代理上,工作正常并成功。我使用与 Azure DevOps 相同的参数运行此命令。

日志产生的错误(数百个):

##[error][xUnit.net 00:00:00.0457701] Microsoft.VisualStudio.QualityTools.UnitTestFramework: Catastrophic failure: System.TypeInitializationException: The type initializer for 'Xunit.DiaSession' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Reflection.TypeExtensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

##[error] at Xunit.DiaSession..cctor() ##[error] --- End of inner exception stack trace --- ##[error] at Xunit.DiaSession..ctor(String assemblyFileName) ##[error] at Xunit.DiaSessionWrapper..ctor(String assemblyFilename) in C:\projects\xunit\src\xunit.runner.utility\Utility\DiaSessionWrapper_DotNet.cs:line 16

##[error] at Xunit.XunitFrontController..ctor(AppDomainSupport appDomainSupport, String assemblyFileName, String configFileName, Boolean shadowCopy, String shadowCopyFolder, ISourceInformationProvider sourceInformationProvider, IMessageSink diagnosticMessageSink) in C:\projects\xunit\src\xunit.runner.utility\Frameworks\XunitFrontController.cs:line 64

##[error] at Xunit.Runner.VisualStudio.TestAdapter.VsTestRunner.RunTestsInAssembly(IRunContext runContext, IFrameworkHandle frameworkHandle, LoggerHelper logger, TestPlatformContext testPlatformContext, IMessageSinkWithTypes reporterMessageHandler, AssemblyRunInfo runInfo) in C:\projects\xunit\src\xunit.runner.visualstudio\VsTestRunner.cs:line 458



构建总结

Total tests: 3679 Passed: 3675 Skipped: 4 Total time: 3.4993 Minutes Vstest.console.exe exited with code 1.



在日志的顶部,在测试步骤的初始化期间:

Multiple versions of same extension found. Selecting the highest version. Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter : 14.0.2505.1 xunit.runner.visualstudio.dotnetcore.testadapter : 99.99.99.0 xunit.runner.visualstudio.testadapter : 99.99.99.0



管道
pool:
name: Dedicated VS2017
demands:
- msbuild
- visualstudio
- vstest

steps:
- task: gittools.gitversion.gitversion-task.GitVersion@3
displayName: GitVersion
inputs:
updateAssemblyInfo: true

- task: NuGetToolInstaller@0
displayName: 'Use NuGet 4.3.0'

- task: NuGetCommand@2
displayName: 'NuGet restore Shamrock.Web'
inputs:
restoreSolution: '$(Parameters.solution)'

- task: Npm@1
displayName: 'npm install Documenta'
inputs:
workingDir: src/Documenta/Documenta.Web/ClientApp
verbose: false
enabled: false

- task: Npm@1
displayName: 'npm build Documenta/ClientApp'
inputs:
command: custom
workingDir: src/Documenta/Documenta.Web/ClientApp
verbose: false
customCommand: 'run build'
enabled: false

- task: Npm@1
displayName: 'npm install Shamrock.Web/Angular'
inputs:
workingDir: src/Shamrock.Web/Shamrock.Web/Angular
verbose: false
enabled: false

- task: Npm@1
displayName: 'npm build Shamrock.Web/Angular'
inputs:
command: custom
workingDir: src/Shamrock.Web/Shamrock.Web/Angular
verbose: false
customCommand: 'run build'
enabled: false

- task: VSBuild@1
displayName: 'Build solution'
inputs:
solution: src/Shamrock.Web/Shamrock.Web.sln
msbuildArgs: '/p:SEPrecompilerIncludeRazor=true /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
clean: true
maximumCpuCount: true

- task: VSBuild@1
displayName: 'Build solution D365'
inputs:
solution: src/Shamrock.D365/Shamrock.D365.sln
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
maximumCpuCount: true
enabled: false

- task: VSBuild@1
displayName: 'Build solution Documenta'
inputs:
solution: src/Documenta/Documenta.sln
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
maximumCpuCount: true
enabled: false

- task: VSTest@2
displayName: 'Test Assemblies'
inputs:
testAssemblyVer2: |
**\$(BuildConfiguration)\*tests.dll
!**\obj\**
!**\*testadapter.dll
vsTestVersion: 16.0
runInParallel: false
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
diagnosticsEnabled: True

- task: CopyFiles@2
displayName: 'Copy DACPAC'
inputs:
Contents: '**\*.dacpac'
TargetFolder: '$(build.artifactstagingdirectory)'

- task: CopyFiles@2
displayName: 'Copy Database Publish Profile'
inputs:
Contents: '**\Shamrock.Database.publish.xml'
TargetFolder: '$(build.artifactstagingdirectory)'

- task: PublishSymbols@1
displayName: 'Publish symbols path'
inputs:
SearchPattern: '**\bin\**\*.pdb'
enabled: false
continueOnError: true

- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
ArtifactName: '$(Parameters.ArtifactName)'

最佳答案

仅当“在发生灾难性故障时收集高级诊断”标志设置为 true 时才会出现此问题。 .

确保它关闭,然后它工作正常。

enter image description here

已知问题现已修复:https://developercommunity.visualstudio.com/content/problem/763234/e0434352clr-issues.html

2020 年 1 月 7 日更新

这个问题再次出现,即使我们将上述标志设置为 false。

我们这次找到的解决方案是在管道中添加一个工具安装程序步骤,并在测试步骤中使用它。

UI 中的工具安装程序步骤

enter image description here

使用正确的测试平台版本
enter image description here

关于c# - 在 Azure DevOps 中运行时,.Net/VS 测试运行器失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58305865/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com