Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static web assets breaking change with .razor.js files #34577

Closed
danroth27 opened this issue Jul 21, 2021 · 3 comments
Closed

Static web assets breaking change with .razor.js files #34577

danroth27 opened this issue Jul 21, 2021 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components feature-static-web-assets

Comments

@danroth27
Copy link
Member

In the Picture Fixer sample app there's some custom logic to handle a .razor.js file as a static web asset which appear to be broken now with .NET 6 Preview 7. A .NET 6 Preview 7 version of Picture Fixer can be found here: https://github.com/danroth27/PictureFixer/tree/net6p7.

Here's the custom logic:

  <ItemGroup>
    <!-- Make any .js files in Pages or Shared available as static content -->
    <JavaScriptModules Include="Pages\**\*.js; Shared\**\*.js" RelativePath="%(Identity)" />
    <StaticWebAsset Include="@(JavaScriptModules->'%(FullPath)')" SourceType="" SourceId="$(PackageId)" RelativePath="%(RelativePath)" BasePath="$(StaticWebAssetBasePath)" ContentRoot="$(MSBuildProjectDirectory)" />
  </ItemGroup>
System.InvalidOperationException: Unknown source type '' for 'C:\Users\daroth\Documents\GitHub\SteveSandersonMS\PictureFixer\PictureFixer\Client\Pages\Editor\EditImage.razor.js'.
   at Microsoft.AspNetCore.Razor.Tasks.StaticWebAsset.Validate()
   at Microsoft.AspNetCore.Razor.Tasks.StaticWebAsset.FromTaskItem(ITaskItem item)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at Microsoft.AspNetCore.Razor.Tasks.ComputeReferencedProjectAssets.Execute()

PictureFixer.Client	C:\Program Files\dotnet\sdk\6.0.100-preview.7.21369.19\Sdks\Microsoft.NET.Sdk.Razor\build\netstandard2.0\Microsoft.NET.Sdk.Razor.StaticWebAssets.targets	668	

@javiercn Can you confirm whether this breaking change is intentional?

@mkArtakMSFT mkArtakMSFT added area-blazor Includes: Blazor, Razor Components feature-static-web-assets labels Jul 21, 2021
@javiercn
Copy link
Member

@danroth27 Yes,

SoureceType needs to be Discovered.

It's not normal that folks define assets this way, this fails here because of how it was defined. We already upgrade existing V1 assets in packages; I don't mind if we upgrade existing asset definitions in the csproj files, but I would prefer if we give you instructions on how to update them to slowly phase out the old format/metadata.

As I mentioned, its not a common operation to do this here and it can be solved quickly.

@danroth27
Copy link
Member Author

I tried setting SourceType to Discovered and then I hit this error:

System.InvalidOperationException: The 'OriginalItemSpec' for the asset must be defined for 'C:\Users\daroth\Documents\GitHub\SteveSandersonMS\PictureFixer\PictureFixer\Client\Pages\Editor\EditImage.razor.js'.
   at Microsoft.AspNetCore.Razor.Tasks.StaticWebAsset.Validate()
   at Microsoft.AspNetCore.Razor.Tasks.StaticWebAsset.FromTaskItem(ITaskItem item)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at Microsoft.AspNetCore.Razor.Tasks.ComputeReferencedProjectAssets.Execute()	

PictureFixer.Client	C:\Program Files\dotnet\sdk\6.0.100-preview.7.21369.19\Sdks\Microsoft.NET.Sdk.Razor\build\netstandard2.0\Microsoft.NET.Sdk.Razor.StaticWebAssets.targets	668	

@javiercn
Copy link
Member

@danroth27 Yeah, sorry, there was a bit more to it.

        <AssetKind>All</AssetKind>
        <AssetMode>All</AssetMode>
        <AssetRole>Primary</AssetRole>
        <OriginalItemSpec>@(JavaScriptModules->'%(Identity)'))</OriginalItemSpec>

@ghost ghost locked as resolved and limited conversation to collaborators Aug 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components feature-static-web-assets
Projects
None yet
Development

No branches or pull requests

3 participants