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
505 stars 195 forks source link

The file X is not a descendent of the base path (Blazor Webassembly) #4614

Open inf9144 opened 4 years ago

inf9144 commented 4 years ago

Our project setup for all our C#-Projects is splitted in different csproj files and folders like this: .\Base\B\C\D\SomeProjectBase.csproj .\CustomerFolder\B\C\D\SomeProject.csproj NonBase does import base project file. So all our razor files from the base code are somwhere under .\Base\B\C\D\**\*.razor and the others are under .\CustomerFolder\B\C\D\**\*.razor when i now open some razor file of the base folder i get the following error and intellisense does not work: "The file X is not a descendent of the base path" Why would it need to be a descendent of the base path? Thats a huge problem for our project toolchain.

Addtional infos: We set the following properties:

        <EnableDefaultCompileItems>False</EnableDefaultCompileItems>
        <EnableDefaultApplicationDefinition>False</EnableDefaultApplicationDefinition>
        <EnableDefaultPageItems>False</EnableDefaultPageItems>

The razor files are included like this:

    <Content Include="$(OurBasePath)Base\B\C\D\**\*.razor;**\*.razor" Exclude="$(OurExcludePattern)">
       <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
javiercn commented 4 years ago

@inf9144 thanks for contacting us.

@pranavkm do we support Link on razor files?

pranavkm commented 4 years ago

Given the error is from the default project system which the compiler does not use, my guess is that dotnet build would work, but tooling is busted. Is that the case @inf9144?

/cc @NTaylorMullen \ @ajaybhargavb \ @ryanbrandenburg

inf9144 commented 4 years ago

Indeed dotnet build and dotnet publish work - just problematic with Visual Studio. Got another problem on publish via Visual Studio: Not all files and directories are created. As example _framework/_bin is missing.

inf9144 commented 4 years ago

In case it helps: Building with MSBuild using the vs solution file does work too.

gmnenad commented 4 years ago

It is not only for WASM, linked *.razor files in Page folder do not work for standard server version either.

I have solution with server and WASM projects sharing common files, using links. That works for .cs files in root of projects, but does not work for Pages/.razor files.

What works:

What does NOT work is:

  1. pages are not working in runtime ("Sorry, there's nothing at this address.")
  2. intellisense in HTML section of those Pages/*.razor files, with following errors :
    • "not a descendent of the base path" ... this error is not in Error List, but as exception reported by VisualStudio for extension (top of VS window)
    • The type or namespace name 'DialogService' could not be found ... for @inject DialogService dialogService
    • Found markup element with unexpected name 'XYZ' .... when blazor component from linked file is used
gmnenad commented 4 years ago

Just to add that it does not work for linked files under wwwroot either ( css or js files for example )

So far it only worked with linked cs files in root folder of the projects.

user72356 commented 4 years ago

I'm having this problem too when deploying a Nuget I made, which includes razor components shipped as files (not compiled in a dll). Because the nuget files are included in the user project as links, VS goes nuts and throws exceptions telling me the razor files are not descendents of the base path. I also ship a .cs file as part of this Nuget and this one works no problem.

Fin3 commented 3 years ago

hello guys,

we are just having the same issue with a linked cshtml file.

We are using this kind of tree:

Inside the Project_Shared there is the _layout.cshtml and _layout.cshtml.cs, that we've linked in project1 and project2.
When we try to edit the _layout.cshtml from the two projects 1-2 we get the same error

System.InvalidOperationException: The file X is not a descendent of the base path Y in Microsoft.AspNetCore.Razor.Language.DefaultRazorProjectFileSystem.GetItem(String path, String fileKind)...

Anyway compile just fine and run without issue, only intellisense in visualstudio is broken.