Использование задачи TransformXml для файла resx, который является встроенным ресурсом

Кто-нибудь имел опыт выполнения преобразования xml в файлах resx раньше? Я хотел бы преобразовать файл resx для каждой конфигурации. Файл преобразования каждой конфигурации может заменить некоторые строковые значения в файле ресурсов. Например:

<None Include="Resources\Label.Release.resx.config">
  <DependentUpon>Label.resx</DependentUpon>
</None>
<EmbeddedResource Include="Resources\Label.resx">
  <Generator>PublicResXFileCodeGenerator</Generator>
  <LastGenOutput>Label.Designer.cs</LastGenOutput>
</EmbeddedResource>

Я пытаюсь преобразовать некоторые значения данных в файле resx. В Label.Release.resx.cofing:

<?xml version="1.0" encoding="utf-8" ?>
<root xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <data name="Title" xml:space="preserve"  xdt:Locator="Match(name)">
    <value  xdt:Tranform="Replace">CEO</value>
  </data> 
</root>

Я попытался поиграть с этим в задаче BeforeBuild:

<Target Name="BeforeBuild">
<MakeDir Directories="$(IntermediateOutputPath)\Resources" 
    Condition="!Exists('$(IntermediateOutputPath)\Resources')"/>
<TransformXml Source="Resources\Label.resx" Transform="Resources\Label.$(Configuration).resx.config" Destination="$(IntermediateOutputPath)\Resources\Label.resx" />

The Label.resx that results in $(IntermediateOutputPath)\Resources folder after has had no transformation. I'm also not sure if that's the location that I would output the transformation result to because Lable.resx should be an embedded resorce in the end.

любая помощь приветствуется


person Liao    schedule 23.08.2012    source источник


Ответы (1)


Вот что я в итоге сделал:

<Target Name="TransLabel">
<MakeDir Directories="$(IntermediateOutputPath)\Resources" Condition="!Exists('$(IntermediateOutputPath)\Resources')" />
<TransformXml Source="Resources\Label.resx" Transform="Resources\Label.$(Configuration).resx.config" Destination="$(IntermediateOutputPath)\Resources\Label.resx" />
<GenerateResource Sources="$(IntermediateOutputPath)\Resources\Label.resx" OutputResources="@(Resx->'$(IntermediateOutputPath)%(Identity).resources')">
</GenerateResource>
<Copy OverwriteReadOnlyFiles="true" SourceFiles="$(IntermediateOutputPath)\Resources\Label.resources" DestinationFiles="$(IntermediateOutputPath)\Ccwa.Resources.Label.resources" />
<RemoveDir Directories="$(IntermediateOutputPath)\Resources" />
</Target>

<Target Name="AfterResGen">
<CallTarget Targets="TransLabel" />

I transform the resx file by hooking into the AfterResGen target, in which the normal resource generating process has taken place. Then I perform my own transformation and generate my own resource file. Then I replace the one already generated before the transformation. When the build continues and the project dll is generated, my transformed resource file is picked up.

person Liao    schedule 27.08.2012