dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.88k stars 4.01k forks source link

error RZ3600: Invalid value ''' for RazorLangVersion. Valid values include 'Latest' or a valid version in range 1 .0 to 8.0 #74410

Closed bouchraRekhadda closed 3 weeks ago

bouchraRekhadda commented 1 month ago

Building an ASP .NET Core project with <GenerateMSBuildEditorConfigFile>false</GenerateMSBuildEditorConfigFile> using .NET SDK produces the error

error RZ3600: Invalid value ''' for RazorLangVersion. Valid values include 'Latest' or a valid version in range 1 .0 to 8.0

To Reproduce

A reproduction sample is available at https://github.com/bouchraRekhadda/web-sample, to reproduce, make sure you build using .NET 8 SDK : dotnet build WebProject.csproj

Excpected behavior

Build succeeded. 0 Warning(s) 0 Error(s)

Actual behavior

CSC : error RZ3600: Invalid value ''' for RazorLangVersion. Valid values include 'Latest' or a valid version in range 1 .0 to 8.0.

Further technical details

baronfel commented 1 month ago

This doesn't repro in 8.0.1xx but does in 8.0.2xx onwards - @333fred I don't see the RazorLangVersion parameter on the Csc Task bundled in the 8.0.2xx SDK at all - have you seen anything like this before?

baronfel commented 1 month ago

@bouchraRekhadda can I ask why you set this property? Disabling this generation mechanism renders all of the Roslyn Analyzers and Source Generators in use in your project nonfunctional - they all rely on this mechanism to get data from the build. When you toggle this you fundamentally alter the code the compiler generates for your project in a way that is very hard (read: near impossible) to recreate.

bouchraRekhadda commented 1 month ago

This doesn't repro in 8.0.1xx but does in 8.0.2xx onwards

Ok thank you for info; my bad I haven't tested on 8.0.1xx.

can I ask why you set this property? Disabling this generation mechanism renders all of the Roslyn Analyzers and Source Generators in use in your project nonfunctional

As mentioned in web-sample#Description we have disabled this property as it fails our CI/CD builds because MSBuild is unable to generate the file : paths are too long exceeding 260 characters. We were OK with disabling this mainly because we have disabled Roslyn analyzers during build and more importantly we were (and still) unable to shorten our +800 projects paths in the repository (projects are structured under several folders following a business logic that would be hard to change).

baronfel commented 1 month ago

Ok, so then the request here is for the Roslyn targets to create this file using a shorter name. We've got some prior art in MSBuild that the Roslyn team can ping us for, but I'll transfer this to Roslyn for followup there and that team can reach out if they'd like the pointers.

bouchraRekhadda commented 1 month ago

Ok, so then the request here is for the Roslyn targets to create this file using a shorter name

That and understanding why this wasn't an issue on .NET 6 or 8.0.1xx SDKs

baronfel commented 1 month ago

@jjonescz may be able to shed some light on that - my guess is that this diagnostic changed or wasn't enabled on those versions. New generators and analyzers are changed with every release, it's not something I'd worry too much about.

jjonescz commented 1 month ago

my guess is that this diagnostic changed or wasn't enabled on those versions

Yes, this diagnostic was broken at some point and fixed in https://github.com/dotnet/razor/pull/9605.

333fred commented 1 month ago

Can I ask why you can't turn on long path support in your CI/CD? I'd need to see the specific paths involved here, but I don't think we can really change much about them here. I expect the file name is <project path>\.globalconfig, and there's not exactly room for changing that.

bouchraRekhadda commented 1 month ago

I expect the file name is .globalconfig, and there's not exactly room for changing that.

The path is <ci/cd_path>\.build\obj\net6.0-windows\<project>\x64\Release\net6.0-windows\<project>.GeneratedMSBuildEditorConfig.editorconfig. (PS: the obj\net6.0-windows is something we have customized for another reason)

chsienki commented 1 month ago

@bouchraRekhadda It's possible to control the output location of the generated config file via the <GeneratedMSBuildEditorConfigFile> property. I would suggest you set it to something shorter, but ensure its unique per project so generated files don't overwrite each other. For example you might use something like

<GeneratedMSBuildEditorConfigFile>cipath\.build\$(MSBuildProjectName).gen.config</GeneratedMSBuildEditorConfigFile>

Completely disabling the file will cause the Razor generator to break in unexpected ways even if we didn't have the LangVersion error.

333fred commented 3 weeks ago

Going to close this out as by-design.