dotnet / razor

Compiler and tooling experience for Razor ASP.NET Core apps in Visual Studio, Visual Studio for Mac, and VS Code.
https://asp.net
MIT License
507 stars 196 forks source link

Editor config options not populated correctly when project build path includes a symlink? #10574

Open nblumhardt opened 8 months ago

nblumhardt commented 8 months ago

Version Used:

8.0.201 SDK on Ubuntu Linux 22.04

Steps to Reproduce:

(1) Create a folder a (2) In a create an ASP.NET MVC project

dotnet new mvc

(3) Add a second Index.cshtml view in any location other than Home/ (4) Create a symlink directory b which points to a

ln -s ./a ./b

(5) Build the project via the symlinked path

dotnet build ./b/a.csproj

Diagnostic Id: CS8785

Expected Behavior:

Build succeeds cleanly.

Actual Behavior:

Build produces warning and will likely fail at runtime.

CSC : warning CS8785: Generator 'RazorSourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentException' with message 'The hintName 'Index_cshtml.g.cs' of the added source file must be unique within a generator. (Parameter 'hintName')'. [/home/nblumhardt/a/a.csproj]

In the generated editorconfig file, ProjectDir and MSBuildProjectDirectory use the symlink path, while the target paths generated for included files use the resolved path.

I hit this because my source code root is symlinked into a directory under my ~ home dir on another drive. In this repro.GeneratedMSBuildEditorConfig.editorconfig, the paths in question are ~/GitHub and /mnt/data/GitHub, and you can see that both Index.cshtml views end up with the same target path.

is_global = true
build_property.TargetFramework = net8.0
build_property.TargetPlatformMinVersion = 
build_property.UsingMicrosoftNETSdkWeb = true
build_property.ProjectTypeGuids = 
build_property.InvariantGlobalization = 
build_property.PlatformNeutralAssembly = 
build_property.EnforceExtendedAnalyzerRules = 
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = repro
build_property.RootNamespace = repro
build_property.ProjectDir = /home/nblumhardt/GitHub/repro/
build_property.EnableComHosting = 
build_property.EnableGeneratedComInterfaceComImportInterop = 
build_property.RazorLangVersion = 8.0
build_property.SupportLocalizedComponentNames = 
build_property.GenerateRazorMetadataSourceChecksumAttributes = 
build_property.MSBuildProjectDirectory = /home/nblumhardt/GitHub/repro
build_property._RazorSourceGeneratorDebug = 

[/mnt/data/GitHub/repro/Views/Home/Index.cshtml]
build_metadata.AdditionalFiles.TargetPath = SW5kZXguY3NodG1s
build_metadata.AdditionalFiles.CssScope = 

[/mnt/data/GitHub/repro/Views/Home/Privacy.cshtml]
build_metadata.AdditionalFiles.TargetPath = UHJpdmFjeS5jc2h0bWw=
build_metadata.AdditionalFiles.CssScope = 

[/mnt/data/GitHub/repro/Views/Other/Index.cshtml]
build_metadata.AdditionalFiles.TargetPath = SW5kZXguY3NodG1s
build_metadata.AdditionalFiles.CssScope = 

[/mnt/data/GitHub/repro/Views/Shared/Error.cshtml]
build_metadata.AdditionalFiles.TargetPath = RXJyb3IuY3NodG1s
build_metadata.AdditionalFiles.CssScope = 

[/mnt/data/GitHub/repro/Views/Shared/_ValidationScriptsPartial.cshtml]
build_metadata.AdditionalFiles.TargetPath = X1ZhbGlkYXRpb25TY3JpcHRzUGFydGlhbC5jc2h0bWw=
build_metadata.AdditionalFiles.CssScope = 

[/mnt/data/GitHub/repro/Views/_ViewImports.cshtml]
build_metadata.AdditionalFiles.TargetPath = X1ZpZXdJbXBvcnRzLmNzaHRtbA==
build_metadata.AdditionalFiles.CssScope = 

[/mnt/data/GitHub/repro/Views/_ViewStart.cshtml]
build_metadata.AdditionalFiles.TargetPath = X1ZpZXdTdGFydC5jc2h0bWw=
build_metadata.AdditionalFiles.CssScope = 

[/mnt/data/GitHub/repro/Views/Shared/_Layout.cshtml]
build_metadata.AdditionalFiles.TargetPath = X0xheW91dC5jc2h0bWw=
build_metadata.AdditionalFiles.CssScope = b-ewte10s1rc

Building from the resolved path fixes this.

I know this is a fairly loose repro; if it's something that's likely to be fixed/fixable and you need more information from me please just let me know.

dotnet-issue-labeler[bot] commented 8 months ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

Cosifne commented 4 months ago

Transferred to razor.