jsakamoto / Toolbelt.Blazor.I18nText

The class library that provides the ability to localize texts on your Blazor app!
Mozilla Public License 2.0
246 stars 23 forks source link

Incorrect static web assets integration #63

Closed javiercn closed 1 month ago

javiercn commented 2 months ago

Right now this package integrates as follows:

  <Target Name="_ResolveBlazorI18nTextStaticWebAssets" Condition=" $(I18nTextNewStaticWebAssetsArchitecture) " DependsOnTargets="_IncludeGeneratedI18nTextResourceJsons">
    <ItemGroup>
      <_BlazorI18nTextStaticWebAsset Include="@(ContentWithTargetPath)" Condition="$([System.String]::Copy('%(TargetPath)').Replace('/','\').StartsWith('wwwroot\_content\i18ntext\'))" />
      <StaticWebAsset Include="@(_BlazorI18nTextStaticWebAsset)">
        <SourceType>Computed</SourceType>
        <SourceId>$(PackageId)</SourceId>
        <ContentRoot>%(RelativeDir)</ContentRoot>
        <BasePath>/</BasePath>
        <RelativePath>_content/i18ntext/%(FileName)%(Extension)</RelativePath>
        <OriginalItemSpec>%(FullPath)</OriginalItemSpec>
        <AssetKind>All</AssetKind>
        <AssetMode>All</AssetMode>
        <AssetRole>Primary</AssetRole>
      </StaticWebAsset>
    </ItemGroup>
  </Target>

This is problematic because it breaks every time properties are added to static web assets in the SDK on newer versions. If you are generating assets as part of the build, you should instead do something like the snippet below to let static web assets define all the metadata based on the content provided as if it was any other file in the project. This way when we add new metadata your package won't break the pipeline.

<Target Name="MyTarget" BeforeTargets="AssignTargetPaths;ResolveStaticWebAssetsConfiguration">
  <Content Include="dist/**" TargetPath="wwwroot\%(RecursiveDir)%(FileName)%(Extension)" />
</Target>
jsakamoto commented 1 month ago

Hi @Junjun-zhao, I published a new version of the "Blazor I18n Text" NuGet package, ver.13.

https://www.nuget.org/packages/Toolbelt.Blazor.I18nText/13.0.0#releasenotes-body-tab

This version will work with the .NET 9 SDK Preview. Please remember that it is still buggy, especially with the hot-reload, but it will work at least if you rebuild a Blazor project whenever the localized source text files are updated.

Junjun-zhao commented 1 month ago

Thanks @jsakamoto for your update. We have tried and it works after upgrade the "Blazor I18n Text" NuGet package to ver.13.

jsakamoto commented 2 weeks ago

Hi @javiercn,

I followed your advice but encountered a problem in the particular case. So, I logged it to an issue: https://github.com/dotnet/sdk/issues/43120.

Could you look into that logged issue? I really appreciate any help you can provide.