.net test .net core 2.2.0 框架项目中的 Azure Devops 管道错误



我正在使用Azure Devops管道。 从 2020/6/25 开始,发生了错误。

任务:点网测试 错误:框架Microsoft。NETCore.App",则未找到版本"2.2.0"。

我关心的: 成功后,将显示以下内容。

Welcome to .NET Core 3.1!
---------------------
SDK Version: 3.1.300

开始失败时的任务:

Welcome to .NET Core 3.1!
---------------------
SDK Version: 3.1.301

Yml 文件的 dotnet 测试部分如下 版本在错误之前使用。添加了次要版本和补丁版本,但它们不起作用。 我添加了 x86 版本的参数,但它也不起作用。

pool:
vmImage: 'windows-latest'
variables:
solution: '**/TamaWeb.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
#  disable.coverage.autogenerate: 'true'
steps:
- task: NuGetToolInstaller@0
inputs:
versionSpec: '>=5' 
checkLatest: true

- 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: DotNetCoreCLI@2
displayName: dotnet test
inputs:
command: test
# test core version
# version: '2.2'
majorVersion: '3' 
minorVersion: '1' 
patchVersion: '300' 
arguments: '--configuration $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --runtime win-x86'
projects: '**/*[Tt]est/*[Tt]est.csproj'
#   projects: '**/*Test/TamaCoreTest.csproj'
nobuild: true

csproj 文件:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="Moq" Version="4.14.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
<PackageReference Include="NLog" Version="4.7.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..XXXAAA.csproj" />
<ProjectReference Include="..XXXBBB.csproj" />
<ProjectReference Include="..XXXCCC.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.test.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties appsettings_1test_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>
</Project>

是否可以使用 dotnet 测试任务指定上述 SDK 版本? 如果您知道其他解决方案,请提供帮助。

错误:框架Microsoft。NETCore.App",则未找到版本"2.2.0"。

您的测试项目 TargetFramework 是 2.2.0,但在测试任务中指定为 3.1.300

<TargetFramework>netcoreapp2.2</TargetFramework>
task: DotNetCoreCLI@2
displayName: dotnet test
inputs:
command: test
# test core version
# version: '2.2'
majorVersion: '3'   <---
minorVersion: '1'   <---
patchVersion: '300' <--- 

你需要确保项目的 .Net Core 版本在以下版本中相同:

  • 项目的 .csproj 文件

  • 指定运行时或版本的任何任务

  • 应用服务(在 Azure 门户中托管(

.NET Core 2.2 是生命周期的终结。 https://dotnet.microsoft.com/download/dotnet-core/2.2/runtime/?utm_source=getdotnetcore&utm_medium=referral

我也遇到了同样的问题,找到了解决方法,在测试任务添加以下任务之前,

步骤:

  • 任务:UseDotNet@2

    displayName: 'Use .NET Core sdk 2.2.100'

输入: 版本: 2.2.100

它基本上是动态添加 2.2 版本。您可以使用 sdk/运行时。 确保版本与项目中的版本相同。

相关内容

最新更新