Mar*_*lPT 5 azure-devops asp.net-core azure-pipelines azure-repos
我有一个包含多个项目的 .Net 解决方案,包括一个测试项目。当我使用 Azure Devops 模板为解决方案创建管道并连接 Azure Repos Git 并配置 ASP.Net Core (.Net Framework) 时,我得到以下 yml 文件:
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- main
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest@2
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\*test*.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
Run Code Online (Sandbox Code Playgroud)
当我运行 pipline 并到达 VSTest 任务时,运行测试后,它给出以下错误:
##[error]Testhost process for source(s) 'D:\a\1\s\Fazer.UITests\bin\Release\net6.0\Microsoft.TestPlatform.PlatformAbstractions.dll' exited with error: A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Program Files\dotnet'.
##[error]Failed to run as a self-contained app.
##[error] - The application was run as a self-contained app because 'D:\a\1\s\Fazer.UITests\bin\Release\net6.0\testhost.runtimeconfig.json' was not found.
##[error] - If this should be a framework-dependent app, add the 'D:\a\1\s\Fazer.UITests\bin\Release\net6.0\testhost.runtimeconfig.json' file and specify the appropriate framework.
##[error]. Please check the diagnostic logs for more information.
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
Mar*_*lPT 12
经过一段时间的寻找解决方案后,我发现我所要做的就是将任务中的key 的行更改**\*test*.dll为。**\*Tests.dlltestAssemblyVer2VSTest@2
前:
- task: VSTest@2
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
--> **\*test*.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
Run Code Online (Sandbox Code Playgroud)
后:
- task: VSTest@2
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
--> **\*Tests.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
Run Code Online (Sandbox Code Playgroud)
然后管道运行成功!
| 归档时间: |
|
| 查看次数: |
1412 次 |
| 最近记录: |