How to fix Visual Studio "bad compile constant value" error when using the C# 11 Raw String Literals feature?

huangapple go评论84阅读模式
英文:

How to fix Visual Studio "bad compile constant value" error when using the C# 11 Raw String Literals feature?

问题

I'm writing a test method that appears to be reasonable to have a JSON value attributed to a variable. I decided to use the C# 11 Raw String Literals feature to improve the code readability. The thing is Visual Studio still complaining about the usage of this feature and returning the "bad compile constant value" error.

How to fix Visual Studio "bad compile constant value" error when using the C# 11 Raw String Literals feature?

The above value was copied from the Microsoft Docs https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/strings

Info regarding the project:
It's a C# NUnit test project.
I'm using .NET 6 which I know uses C#10 as the default language (as we can see here).
So, using Directory.build.props as directives to build the projects I added to the root build.props file the following line:

<LangVersion>11.0</LangVersion>

The projects in the whole solution compile even using Visual Studio IDE or with the dotnet build command line (and also the tests are passing).

How to fix that?

I tried to determine the default language for the project using visual studio project properties (and it looks like ok).

How to fix Visual Studio "bad compile constant value" error when using the C# 11 Raw String Literals feature?

I also tried the indentation thing as suggested in this answer https://stackoverflow.com/a/75825615/3434514

I'm expecting Visual Studio to recognize the usage of the "Raw string literals declaration."

英文:

I'm writing a test method that appears to be reasonable to have a JSON value attributed to a variable. I decided to use the C# 11 Raw String Literals feature to improve the code readability. The thing is Visual Studio still complaining about the usage of this feature and returning the "bad compile constant value" error.

How to fix Visual Studio "bad compile constant value" error when using the C# 11 Raw String Literals feature?

The above value was copied from the Microsoft Docs https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/strings

Info regarding the project:
It's a C# NUnit test project.
I'm using .NET 6 which I know uses C#10 as the default language (as we can see here).
So, using Directory.build.props as directives to build the projects I added to the root build.props file the following line:


<LangVersion>11.0</LangVersion>

The projects in the whole solution compile even using Visual Studio IDE or with the dotnet build command line (and also the tests are passing).

How to fix that?

I tried to determine the default language for the project using visual studio project properties (and it looks like ok).

How to fix Visual Studio "bad compile constant value" error when using the C# 11 Raw String Literals feature?

I also tried the indentation thing as suggested in this answer https://stackoverflow.com/a/75825615/3434514

I'm expecting to Visual Studio recognize the usage of the usage of """ Raw string literals declaration.

答案1

得分: 1

你需要安装最新版本的JetBrains ReSharper。

英文:

You need the latest version of JetBrains ReSharper installed.

huangapple
  • 本文由 发表于 2023年7月20日 21:06:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76730236.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定