Skip to content

Static assets doesn't serve content files that are linked from a location outside of the project #51392

@DamianEdwards

Description

@DamianEdwards

When creating a Razor Class Library, files that are linked to wwwroot from a different physical location, e.g. a Shared directory one level up from the class library project, result in a 404 when requested via the usual _content/MyRazorClassLib/FileName path.

MyRazorClassLib.csproj

<Project Sdk="Microsoft.NET.Sdk.Razor">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <Content Include="..\Shared\MyIcon.ico" Link="wwwroot\MyIcon.ico" />
  </ItemGroup>

  <ItemGroup>
    <SupportedPlatform Include="browser" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.0-rtm.23512.10" />
  </ItemGroup>

</Project>

Component1.razor

<div class="my-component">
    This component is defined in the <strong>MyRazorClassLib</strong> library.<br />

    <h4>Linked file</h4>
    <img src="_content/MyRazorClassLib/MyIcon.ico" />

    <h4>Physical file</h4>
    <img src="_content/MyRazorClassLib/MyIconPhysical.ico" />
</div>
image image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions