【问题标题】:Using TransformXml task on resx file that is an embeded resource在作为嵌入式资源的 resx 文件上使用 TransformXml 任务
【发布时间】:2012-08-23 23:46:11
【问题描述】:

以前有没有人对 resx 文件执行过 xml 转换?我想为每个配置转换一个 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" />

生成 $(IntermediateOutputPath)\Resources 文件夹后的 Label.resx 没有进行任何转换。我也不确定这是否是我将转换结果输出到的位置,因为 Lable.resx 最终应该是一个嵌入式资源。

感谢任何帮助

【问题讨论】:

    标签: .net asp.net-mvc-3 resx xdt-transform


    【解决方案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" />
    

    我通过挂钩到 AfterResGen 目标来转换 resx 文件,其中发生了正常的资源生成过程。然后我执行我自己的转换并生成我自己的资源文件。然后我替换转换之前已经生成的那个。当构建继续并生成项目 dll 时,我转换的资源文件被拾取。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-29
      • 1970-01-01
      • 1970-01-01
      • 2016-09-09
      • 2016-04-09
      • 2012-01-01
      • 2010-10-02
      • 2013-03-02
      相关资源
      最近更新 更多