CS1617: Invalid option '10' for /langversion
Asked Answered
T

4

6

While building this open source C# project in AppVeyor, I get the error:

CSC : error CS1617: Invalid option '10' for /langversion. Use '/langversion:?' to list supported values.

See the build log.

In build settings, Visual Studio 2022 is selected as the build worker image and the Preinstalled Software page lists both .NET 5 and 6 SDKs for that image.

What am I missing? Why is it using MSBuild 16 and not 17?

Tarrsus answered 2/8, 2022 at 13:10 Comment(6)
The langversion option documentation might help. You should probably tell the author of the project you're using as well, to help them.Tutorial
@HansPassant What do you mean? The build is still failing as evident from the build history: ci.appveyor.com/project/morpher/dawgsharp/historyTarrsus
@HansPassant I am the author of this project and I added <LangVersion>10</LangVersion> just so it errors out early.Tarrsus
@HansPassant What's interesting, one of my other projects (which also uses C# 10) builds fine with the same image: ci.appveyor.com/project/morpher/enumerabletostreamTarrsus
@HansPassant I tried removing Visual Studio version information from the sln file, just like the other project, but AppVeyor still picks MSBuild 16 (as seen from the top of the build log): ci.appveyor.com/project/morpher/dawgsharpTarrsus
The documentation I linked to says that the value should be 10.0. Have you tried that instead of just plain 10?Tutorial
T
1

The problem was that appveyor.yml in the repo had Visual Studio 2019 in it as the worker image. The way AppVeyor works, the yml file takes precedence over UI settings.

Tarrsus answered 3/8, 2022 at 16:46 Comment(1)
I am glad to hear that your problem has been solved, you can consider accepting it as answer. It will also help others to solve the similar issue.Anecdotage
K
6

lanch the solution with VS2022 and that resolve the problem

Kris answered 19/10, 2022 at 20:25 Comment(0)
A
1

According to your description, the error: CSC : error CS1617: Invalid option '10' for /langversion. Use '/langversion:?' to list supported values. is caused by not using C#10 in vs2022 and .NET6.0 environment.

We can see from the build log you provided that the build is using MSBuild16 in VS2019. enter image description here

We can find the MSBuild.exe installed with Visual Studio 2022 Community from C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe.

We have not used AppVeyor. Maybe you can try specifying the path for MSBuild(17) in command line(not sure whether AppVeyor uses command line to build?) to compile it or just select VS2022 and .NET6.0 when you choose build settings.

Anecdotage answered 3/8, 2022 at 6:12 Comment(0)
T
1

The problem was that appveyor.yml in the repo had Visual Studio 2019 in it as the worker image. The way AppVeyor works, the yml file takes precedence over UI settings.

Tarrsus answered 3/8, 2022 at 16:46 Comment(1)
I am glad to hear that your problem has been solved, you can consider accepting it as answer. It will also help others to solve the similar issue.Anecdotage
N
0

Here's the only thing that got it to work for me, for JetBrains Rider 2023.2.2 in Arch Linux:

Inside the .csproj's <PropertyGroup>, I added the following:

    <LangVersion>10.0</LangVersion>
    <TargetFramework>net8.0</TargetFramework>

Then it built successfully.

Then, paradoxically, I removed <TargetFramework>net8.0</TargetFramework> and it still compiles???

Nuclear answered 12/5 at 12:59 Comment(1)
In my case, I had <LangVersion>11.0</LangVersion> I deleted that line and reloaded the solution. It built cleanly. I am using VS2019.Caryophyllaceous

© 2022 - 2024 — McMap. All rights reserved.