.net core Azure-从命令行在代理上运行测试项目

.net core Azure-从命令行在代理上运行测试项目,.net-core,automated-tests,azure-pipelines,azure-devops-self-hosted-agent,.net Core,Automated Tests,Azure Pipelines,Azure Devops Self Hosted Agent,我正在Azure管道上工作,运行在Windows自托管代理上,在防火墙后面运行自动测试 去年12月,我就相关问题提出了问题,并链接到我收到的错误消息:“{”代码“:“无法在本地获取发卡机构证书”}” 我仍然有这个错误,我相信它可能与代理的防火墙有关,但我试图从不同的角度来看待这个问题 我想在Dotnet Core 3.1项目上运行一个测试项目,在一个自托管代理上,我有Dotnet SDK 5.0,我看到一条消息,说3.1即将不再受支持,但我无法迁移该应用程序,我在3.1下还有其他应用程序需要构建

我正在Azure管道上工作,运行在Windows自托管代理上,在防火墙后面运行自动测试

去年12月,我就相关问题提出了问题,并链接到我收到的错误消息:“{”代码“:“无法在本地获取发卡机构证书”}”

我仍然有这个错误,我相信它可能与代理的防火墙有关,但我试图从不同的角度来看待这个问题

我想在Dotnet Core 3.1项目上运行一个测试项目,在一个自托管代理上,我有Dotnet SDK 5.0,我看到一条消息,说3.1即将不再受支持,但我无法迁移该应用程序,我在3.1下还有其他应用程序需要构建测试管道

我在代理上安装了.Net Core 3.1,但作为一名.Net 2开发人员,这对我来说是新的,我发现我在代理上有以下版本:

C:\>dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.100
 Commit:    5044b93829

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\...\sdk\5.0.100\

Host (useful for support):
  Version: 5.0.0
  Commit:  cf258a14b7

.NET SDKs installed:
  3.1.301 [C:\...\sdk]
  5.0.100 [C:\...\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.23 [C:\...\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.23 [C:\...\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.5 [C:\...\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.9 [C:\...\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0 [C:\...\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.23 [C:\...\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.5 [C:\...\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.9 [C:\...\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0 [C:\...\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.5 [C:\...\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.9 [C:\...\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.0 [C:\...\Microsoft.WindowsDesktop.App]
我认为如果管道中的任务无法运行我的测试项目,我应该从代理服务器上的命令行尝试,但是,我不知道是否应该设置要使用的版本

我试过这个命令:

E:\test>dotnet test E:\Agent\_work\01\s\src\SolutionFolder\ProjectFolder\TestProject.csproj
要获得此输出,请执行以下操作:

C:\dotnet\sdk\5.0.100\NuGet.targets(131,5): error : Unable to load the service index for source https://ourFeed.pkgs.visualstudio.com/33706eec-...4c4/_packaging/UpstreamFeed/nuget/v3/index.json. 
C:\dotnet\sdk\5.0.100\NuGet.targets(131,5): error :   Response status code does not indicate success: 401 (Unauthorized). 
为了连接到Nuget,我们使用一个配置了Nuget的提要,管道应该使用这个提要来连接它,防火墙阻止直接链接到Nuget。这适用于建造管道

在解决方案的根目录下,我有一个nuget.config文件,我还将其作为测试复制到测试项目中:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="ArtifactRepo" value=" https://ourFeed.pkgs.visualstudio.com/33706eec-...4c4/_packaging/UpstreamFeed/nuget/v3/index.json " />
  </packageSources>
  <config>
        <add key="http_proxy" value="http://proxy.xxx:443" />
        <add key="https_proxy" value="https://proxy.xxx:443" />
  </config>
</configuration> 
我运行了命令:“
dotnet test[path to csproj file]
”,得到了一个我没有记录的错误,可能是“401(未经授权)”或“无法在本地获取颁发者证书”

我添加了上面添加的nuget.config文件

我在浏览器中测试了该提要的URL,但被安全性阻止,我将该URL添加到受信任的站点,在浏览器中再次测试了该提要URL,但出现了相同的错误

我再次测试了“
dotnet测试[csproj文件路径]
”,现在它工作了
我删除了nuget.config和global.json文件,它仍然有效
我不明白这一点,是受信任的网站,还是一旦它从文件中读取并将所需数据保存到某个地方……也许你会明白这一点

测试本身失败,但dotnet测试命令行可以工作:

失败:29,通过:0,跳过:0,总计:29, 持续时间:1秒-MyProject.Test.Core.dll(netcoreapp3.1)

现在,运行管道,在使用powershell脚本添加步骤后,将创建global.json文件,但我仍然有问题:

Results File: E:\Agent\_work\_temp\[***]_2021-02-05_11_53_38.trx
Failed!  - Failed:    29, Passed:     0, Skipped:     0, Total:    29, Duration: 1 s - [***].Core.dll (netcoreapp3.1)
项目中的29个错误可能与安全性有关,但我应该在Azure中获得错误报告,对吗

我可以看到在E:\Agent\u work\u temp\中生成的TRX文件,但随后它们消失,出现更多错误,这是安全性问题吗?他们告诉我他们打开了服务器和Azure之间的通道…你知道为什么我没有得到测试报告和代码覆盖率报告吗

仍然有关于Net5存在一些兼容性问题的警告。 以下是它开始失败的日志:

##[debug]Exit code 1 received from tool 'C:\Program Files\dotnet\dotnet.exe'
##[debug]Processed: ##vso[task.issue type=error;]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1
##[debug]BuildConfiguration=undefined
##[debug]BuildPlatform=undefined
##[debug]testRunTitle=ProjectTests
##[debug]defaultRoot: 'E:\Agent\_work\_temp'
##[debug]findOptions.allowBrokenSymbolicLinks: 'false'
##[debug]findOptions.followSpecifiedSymbolicLink: 'true'
##[debug]findOptions.followSymbolicLinks: 'true'
##[debug]matchOptions.debug: 'false'
##[debug]matchOptions.nobrace: 'true'
##[debug]matchOptions.noglobstar: 'false'
##[debug]matchOptions.dot: 'true'
##[debug]matchOptions.noext: 'false'
##[debug]matchOptions.nocase: 'true'
##[debug]matchOptions.nonull: 'false'
##[debug]matchOptions.matchBase: 'false'
##[debug]matchOptions.nocomment: 'false'
##[debug]matchOptions.nonegate: 'false'
##[debug]matchOptions.flipNegate: 'false'
##[debug]pattern: '**/*.trx'
##[debug]findPath: 'E:\Agent\_work\_temp'
##[debug]statOnly: 'false'
##[debug]findPath: 'E:\Agent\_work\_temp'
##[debug]findOptions.allowBrokenSymbolicLinks: 'false'
##[debug]findOptions.followSpecifiedSymbolicLink: 'true'
##[debug]findOptions.followSymbolicLinks: 'true'
##[debug]  E:\Agent\_work\_temp (directory)
##[debug]  E:\Agent\_work\_temp\.taskkey (file)
##[debug]  E:\Agent\_work\_temp\1a672b68-2897-472e-8574-05442c3ded4d.ps1 (file)
##[debug]  E:\Agent\_work\_temp\[***]_2021-02-05_11_53_38.trx (file)
##[debug]  E:\Agent\_work\_temp\Deploy_[***] 2021-02-05 11_53_37 (directory)
##[debug]  E:\Agent\_work\_temp\Deploy_[***] 2021-02-05 11_53_37\In (directory)
##[debug]  E:\Agent\_work\_temp\Deploy_[***] 2021-02-05 11_53_37\In\[***] (directory)
##[debug]7 results
##[debug]found 7 paths
##[debug]applying include pattern
##[debug]adjustedPattern: 'E:\Agent\_work\_temp\**/*.trx'
##[debug]1 matches
##[debug]1 final results
##[debug]Failed to get FF TestManagement.Server.UsePublishTestResultsLibInAgent Value.
Unable to get the FF: TestManagement.Server.EnablePublishToTcmServiceDirectlyFromTask. Reason: One or more errors occurred. (Moved Temporarily)
##[debug]Failed to get FF TestManagement.PTR.CalculateTestRunSummary Value.
##[debug]Reading test results from file 'E:\Agent\_work\_temp\[***]_2021-02-05_11_53_38.trx'
##[debug]Setting run start and finish times.
##[debug]Attachment location: E:\Agent\_work\_temp\[***]_2021-02-05_11_53_38\In
##[debug]Total test results: 29
##[debug]Processed: ##vso[results.publish type=VSTest;mergeResults=false;runTitle=[***];publishRunAttachments=true;resultFiles=E:\Agent\_work\_temp\[***]_2021-02-05_11_53_38.trx;testRunSystem=VSTS - dotnet;]
##[warning].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build
##[debug]Processed: ##vso[task.issue type=warning;].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build
Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
##[debug]task result: Failed
##[error]Dotnet command failed with non-zero exit code on the following projects : E:\Agent\_work\31\s\src\[***]Core\[***].Core.csproj
##[debug]Processed: ##vso[task.issue type=error;]Dotnet command failed with non-zero exit code on the following projects : E:\Agent\_work\31\s\src\[***].Core\[***].Core.csproj
##[debug]Processed: ##vso[task.complete result=Failed;]Dotnet command failed with non-zero exit code on the following projects : E:\Agent\_work\31\s\src\[***].Core\[***].Core.csproj
##[section]Async Command Start: Publish test results
##[warning]Failed to publish test results: Moved Temporarily
##[section]Async Command End: Publish test results
##[section]Finishing: Tests
##[debug]退出从工具“C:\Program Files\dotnet\dotnet.exe”收到的代码1
##[调试]已处理:##vso[task.issue type=error;]错误:进程“C:\Program Files\dotnet\dotnet.exe”失败,退出代码为1
##[debug]BuildConfiguration=未定义
##[debug]BuildPlatform=未定义
##[调试]testRunTitle=ProjectTests
##[debug]defaultRoot:'E:\Agent\\u work\\u temp'
##[debug]findOptions.allowBrokenSymbolicLinks:'false'
##[debug]findOptions.followsSpecifiedSymbolicClink:'true'
##[debug]findOptions.followSymbolicLinks:'true'
##[debug]matchOptions.debug:'false'
##[debug]matchOptions.nobrace:'true'
##[debug]matchOptions.noglobstar:'false'
##[debug]matchOptions.dot:'true'
##[debug]matchOptions.noext:“false”
##[debug]matchOptions.nocase:'true'
##[debug]matchOptions.nonull:“false”
##[debug]matchOptions.matchBase:“false”
##[debug]matchOptions.nocomment:'false'
##[debug]matchOptions.nonegate:“false”
##[debug]matchOptions.flipNegate:'false'
##[调试]模式:'***.trx'
##[调试]查找路径:“E:\Agent\\u work\\u temp”
##[调试]静态:“错误”
##[调试]查找路径:“E:\Agent\\u work\\u temp”
##[debug]findOptions.allowBrokenSymbolicLinks:'false'
##[debug]findOptions.followsSpecifiedSymbolicClink:'true'
##[debug]findOptions.followSymbolicLinks:'true'
##[调试]E:\Agent\\u work\\u temp(目录)
##[调试]E:\Agent\\u work\\u temp\.taskkey(文件)
##[调试]E:\Agent\\工作\临时\1a672b68-2897-472e-8574-05442c3ded4d.ps1(文件)
##[debug]E:\Agent\\工作\\临时\[***]\\ U 2021-02-05\\ U 11\\ U 53\\ U 38.trx(文件)
##[调试]E:\Agent\\工作\临时\部署\[***]2021-02-05 11\u 53\u 37(目录)
##[调试]E:\Agent\\u work\\u temp\Deploy\u[***]2021-02-05 11\u 53\u 37\In(目录)
##[debug]E:\Agent\\\工作\ \临时\部署\[***]2021-02-05 11\[***]中的\[***]目录
##[调试]7个结果
##[调试]找到7个路径
##[调试]应用包含模式
##[调试]调整模式:“E:\Agent\\u work\\u temp\***.trx”
##[调试]1个匹配项
##[调试]1最终结果
##[debug]无法获取FF TestManagement.Server.UsePublishTestResultsLibInAgent值。
无法从任务直接获取FF:TestManagement.Server.EnablePublishToTCMServiceFromTask。原因:发生了一个或多个错误。(暂时移动)
##[debug]无法获取FF TestManagement.PTR.CalculateStructureMary值。
##[调试]从文件“E:\Agent\\u work\\u temp\[***]\u 2021-02-05\u 11\u 53\u 38.trx”读取测试结果
##[调试]设置运行开始和完成时间。
##[调试]附件位置:E:\Agent\\u work\\u temp\[***]\u 2021-02-05\u 11\u 53\u 38\In
##[调试]总测试结果:29
##[debug]已处理:##vso[results.publish type=VSTest;mergeResults=false;runTitle=[***];publishRunAttachments=true;resultFiles=E:\Agent\\u work\\u temp\[***]\u 2021-02-05\u 11\u 53\u 38.trx;testRunSystem=VSTS-dotnet;]

##[警告].NET 5与较旧的Nuget版本存在一些兼容性问题(我检查了另一个
使用dotnet任务的线程
未能安装
dotnet cor
##[debug]Exit code 1 received from tool 'C:\Program Files\dotnet\dotnet.exe'
##[debug]Processed: ##vso[task.issue type=error;]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1
##[debug]BuildConfiguration=undefined
##[debug]BuildPlatform=undefined
##[debug]testRunTitle=ProjectTests
##[debug]defaultRoot: 'E:\Agent\_work\_temp'
##[debug]findOptions.allowBrokenSymbolicLinks: 'false'
##[debug]findOptions.followSpecifiedSymbolicLink: 'true'
##[debug]findOptions.followSymbolicLinks: 'true'
##[debug]matchOptions.debug: 'false'
##[debug]matchOptions.nobrace: 'true'
##[debug]matchOptions.noglobstar: 'false'
##[debug]matchOptions.dot: 'true'
##[debug]matchOptions.noext: 'false'
##[debug]matchOptions.nocase: 'true'
##[debug]matchOptions.nonull: 'false'
##[debug]matchOptions.matchBase: 'false'
##[debug]matchOptions.nocomment: 'false'
##[debug]matchOptions.nonegate: 'false'
##[debug]matchOptions.flipNegate: 'false'
##[debug]pattern: '**/*.trx'
##[debug]findPath: 'E:\Agent\_work\_temp'
##[debug]statOnly: 'false'
##[debug]findPath: 'E:\Agent\_work\_temp'
##[debug]findOptions.allowBrokenSymbolicLinks: 'false'
##[debug]findOptions.followSpecifiedSymbolicLink: 'true'
##[debug]findOptions.followSymbolicLinks: 'true'
##[debug]  E:\Agent\_work\_temp (directory)
##[debug]  E:\Agent\_work\_temp\.taskkey (file)
##[debug]  E:\Agent\_work\_temp\1a672b68-2897-472e-8574-05442c3ded4d.ps1 (file)
##[debug]  E:\Agent\_work\_temp\[***]_2021-02-05_11_53_38.trx (file)
##[debug]  E:\Agent\_work\_temp\Deploy_[***] 2021-02-05 11_53_37 (directory)
##[debug]  E:\Agent\_work\_temp\Deploy_[***] 2021-02-05 11_53_37\In (directory)
##[debug]  E:\Agent\_work\_temp\Deploy_[***] 2021-02-05 11_53_37\In\[***] (directory)
##[debug]7 results
##[debug]found 7 paths
##[debug]applying include pattern
##[debug]adjustedPattern: 'E:\Agent\_work\_temp\**/*.trx'
##[debug]1 matches
##[debug]1 final results
##[debug]Failed to get FF TestManagement.Server.UsePublishTestResultsLibInAgent Value.
Unable to get the FF: TestManagement.Server.EnablePublishToTcmServiceDirectlyFromTask. Reason: One or more errors occurred. (Moved Temporarily)
##[debug]Failed to get FF TestManagement.PTR.CalculateTestRunSummary Value.
##[debug]Reading test results from file 'E:\Agent\_work\_temp\[***]_2021-02-05_11_53_38.trx'
##[debug]Setting run start and finish times.
##[debug]Attachment location: E:\Agent\_work\_temp\[***]_2021-02-05_11_53_38\In
##[debug]Total test results: 29
##[debug]Processed: ##vso[results.publish type=VSTest;mergeResults=false;runTitle=[***];publishRunAttachments=true;resultFiles=E:\Agent\_work\_temp\[***]_2021-02-05_11_53_38.trx;testRunSystem=VSTS - dotnet;]
##[warning].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build
##[debug]Processed: ##vso[task.issue type=warning;].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build
Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
##[debug]task result: Failed
##[error]Dotnet command failed with non-zero exit code on the following projects : E:\Agent\_work\31\s\src\[***]Core\[***].Core.csproj
##[debug]Processed: ##vso[task.issue type=error;]Dotnet command failed with non-zero exit code on the following projects : E:\Agent\_work\31\s\src\[***].Core\[***].Core.csproj
##[debug]Processed: ##vso[task.complete result=Failed;]Dotnet command failed with non-zero exit code on the following projects : E:\Agent\_work\31\s\src\[***].Core\[***].Core.csproj
##[section]Async Command Start: Publish test results
##[warning]Failed to publish test results: Moved Temporarily
##[section]Async Command End: Publish test results
##[section]Finishing: Tests
steps:
- powershell: |
   
   dotnet new globaljson --sdk-version 3.1.9 --force 
   
  displayName: 'PowerShell Script'