- 
                Notifications
    You must be signed in to change notification settings 
- Fork 549
Open
Open
Copy link
Labels
bugIf an issue is a bug or a pull request a bug fixIf an issue is a bug or a pull request a bug fix
Milestone
Description
Project file:
<Project Sdk="Microsoft.NET.Sdk.Razor">
  <PropertyGroup>
    <TargetFramework>net9.0-ios</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
  <ItemGroup>
    <SupportedPlatform Include="browser" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="9.0.0" />
  </ItemGroup>
</Project>Building results in:
$ dotnet build /bl
Restore complete (3.6s)
    info NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
  RazorClassLibrary failed with 4 error(s) (0.7s)
    wwwroot/background.png : error
      The path '../../../../../../../../../Users/rolf/test/bugs/RazorClassLibrary/wwwroot/background.png' would result in a file outside of the app bundle and cannot be used.
    wwwroot/exampleJsInterop.js : error
      The path '../../../../../../../../../Users/rolf/test/bugs/RazorClassLibrary/wwwroot/exampleJsInterop.js' would result in a file outside of the app bundle and cannot be used.
    Component1.razor : error
      The path '../../../../../../../../../Users/rolf/test/bugs/RazorClassLibrary/Component1.razor' would result in a file outside of the app bundle and cannot be used.
    _Imports.razor : error
      The path '../../../../../../../../../Users/rolf/test/bugs/RazorClassLibrary/_Imports.razor' would result in a file outside of the app bundle and cannot be used.
Build failed with 4 error(s) in 6.7s
Complete test project: RazorClassLibrary-9528657.zip
Binlog: msbuild.binlog.zip
The reason this happens is that:
- The Blazor SDK adds default Content items.
- We compute the LogicalName metadata for these Content items using the defining file's location, computing the relative path of the Content item relative to the defining file's location.
- Since the defining file in this case is inside the Blazor SDK, the computed relative path ends up being something ridiculous like '../../../../../../../../../Users/rolf/test/bugs/RazorClassLibrary/_Imports.razor' (from above).
The fix seems trivial: compute the LogicalName metadata using the project file's location instead.
This would be a rather big breaking change however, so it shouldn't be done until .NET 11 (or alternatively as an opt-in in a .NET 10 service release, then make it opt-out in .NET 11, and potentially remove the opt-out option completely for .NET 12).
In the meantime, the workaround is to add this to the project file:
<ItemGroup>
    <Content Update="@(Content)" IsDefaultItem="true" />
</ItemGroup>Ref: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2576178
Metadata
Metadata
Assignees
Labels
bugIf an issue is a bug or a pull request a bug fixIf an issue is a bug or a pull request a bug fix