gpt4 book ai didi

testing - 无法在 Azure DevOps 上构建/测试 .NET Core 测试项目 - 无效的 langversion

转载 作者:行者123 更新时间:2023-11-28 19:54:15 25 4
gpt4 key购买 nike

我正在尝试运行 dotnet test在 Azure DevOps 中,但我不断收到此错误:

ControllerTests/v1Tests/FooTests/DetailsAsyncTests.cs(241,64): error CS8107: Feature 'default literal' is not available in C# 7.0. Please use language version 7.1 or greater.

这是我的 .csproj 的开始文件..

<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>7.3</LangVersion>
<PackageId><snipped></PackageId>
<Version>0.0.0</Version>
</PropertyGroup>

...

这是我的 .yml 的开始文件..

name: $(Year:yyyy).$(Month).$(DayOfMonth).$(Rev:r)
pool:
vmImage: 'Ubuntu 16.04'

variables:
buildConfiguration: 'Release'
....

steps

<snip>

- script: |
dotnet test tests/snip/foo1.csproj --configuration $(buildConfiguration) -p:Version=$(Build.BuildNumber)
dotnet test tests/snip/foo2.csproj --configuration $(buildConfiguration) -p:Version=$(Build.BuildNumber)
dotnet test tests/snip/foo3.csproj --configuration $(buildConfiguration) -p:Version=$(Build.BuildNumber)
displayName: 'dotnet test'

...

我也试过 <LangVersion>latest</LangVersion>.csproj .

我已经三重检查项目文件是否包含 <LangVersion>在其中,进行测试的地方。


更新

所以我似乎可以使用它,但我仍然不知道这是一个“hack”解决方案还是正确的解决方案。但是,我仍然不确定为什么会出现此问题。

我添加了 langver作为 msbuild 属性:

dotnet test tests/snip/foo2.csproj 
--configuration $(buildConfiguration)
-p:Version=$(Build.BuildNumber)
-p:langversion=latest

注意最后一个参数...

最佳答案

i'm unsure WHY this problem is happening ... so I would love some help explaining that

有一种情况会导致这个问题,但我不太确定它是否适用于你,你可以检查一下。

当我们设置属性 <LangVersion>7.3</LangVersion> 时在项目文件中,位于 debug 中属性组:

enter image description here

但是当我们在 Azure Devops 中构建它时,我们将构建配置设置为 release , 在你的 .yml文件:

variables:
buildConfiguration: 'Release'
....

这可能是您在使用 Azure Devops 构建时需要再次传递参数(-p:langversion=latest)的原因。

此外,对于所有项目配置(个人),最简单的方法是:

  • 右击 YourProject , 点击 Properties

  • 点击Build如果尚未选择

  • 将配置更改为 All Configurations

  • 点击Advanced ...

  • 更改语言版本

希望这对您有所帮助。

关于testing - 无法在 Azure DevOps 上构建/测试 .NET Core 测试项目 - 无效的 langversion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55506747/

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