arcade icon indicating copy to clipboard operation
arcade copied to clipboard

XliffTasks breaks with strongly generated resources classes

Open rolfbjarne opened this issue 1 year ago • 3 comments

  • [ ] This issue is blocking
  • [ ] This issue is causing unreasonable pain

Enabling generated strongly typed code for resources breaks XliffTasks with:

error MSB3573: The language for a strongly typed resource class was specified, but more than one source file was passed in. Please pass in only one source file at a time if you want to generate strongly typed resource classes.

Test project: xlifftest-e9b5f83.zip To repro: download & unzip & dotnet build

For reference, this is the EmbeddedResource:

<EmbeddedResource Update="Resources.resx">
  <Generator>ResXFileCodeGenerator</Generator>
  <LastGenOutput>Resources.Designer.cs</LastGenOutput>
  <CustomToolNamespace>Resources</CustomToolNamespace>
  <ManifestResourceName>Resources</ManifestResourceName>
  <StronglyTypedFileName>Resources.designer.cs</StronglyTypedFileName>
  <StronglyTypedLanguage>CSharp</StronglyTypedLanguage>
  <StronglyTypedNamespace>Resources</StronglyTypedNamespace>
  <StronglyTypedClassName>Resources</StronglyTypedClassName>
  <GenerateResource>true</GenerateResource>
  <PublicClass>true</PublicClass>
</EmbeddedResource>

Binlog: msbuild.binlog.zip

rolfbjarne avatar Nov 28 '23 10:11 rolfbjarne

This seems to fix it:

<Target Name="FixEmbeddedResources" AfterTargets="TranslateSourceFromXlf">
  <ItemGroup>
    <EmbeddedResource Update="@(EmbeddedResource)" Condition="'%(EmbeddedResource.XlfSource)' != ''">
      <StronglyTypedClassName />
      <StronglyTypedLanguage />
      <StronglyTypedNamespace />
      <StronglyTypedFileName />
    </EmbeddedResource>
  </ItemGroup>
</Target>

rolfbjarne avatar Nov 28 '23 10:11 rolfbjarne

@rolfbjarne please feel free to submit a PR to the repo with this fix. Thanks! :)

missymessa avatar Jan 11 '24 21:01 missymessa

For me the following works in a Dotnet MAUI Project (with both dotnet build and dotnet publish):

<Target Name="GenerateResXClass" AfterTargets="GatherXlf">
  <ItemGroup>
	  <EmbeddedResource Update="Resources\Localization\AppResources.resx">
			  <Generator>ResXFileCodeGenerator</Generator>
			  <LastGenOutput>Resources/Localization/AppResources.Designer.cs</LastGenOutput>
			  <StronglyTypedFileName>Resources/Localization/AppResources.Designer.cs</StronglyTypedFileName>
			  <StronglyTypedLanguage>CSharp</StronglyTypedLanguage>
			  <StronglyTypedNamespace>XXX.Maui.Resources.Localization</StronglyTypedNamespace>
			  <StronglyTypedClassName>AppResources</StronglyTypedClassName>
	  </EmbeddedResource>
  </ItemGroup>
</Target>

After some research I think the problems is that all properties of the EmbeddedResource (e.g. StronglyTypedClassName) are copied to the new TaskItem using the Copy-Constructor: https://github.com/dotnet/arcade/blob/main/src/Microsoft.DotNet.XliffTasks/Tasks/GatherXlf.cs#L39

markusroessler avatar Feb 15 '24 11:02 markusroessler