开发者

C# application not recognizing satellite resource assemblies

开发者 https://www.devze.com 2023-01-09 03:44 出处:网络
Due to the extreme amount of .resx files in our application, I have created the following MSBuild script to compile all language .resx files into .resource, then embed them into satellite resource ass

Due to the extreme amount of .resx files in our application, I have created the following MSBuild script to compile all language .resx files into .resource, then embed them into satellite resource assemblies.

    <Project DefaultTargets="Main" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Res Include = "Dialog\*.ja-JP.resx">
      <Culture>ja-JP</Culture>
      <Project>Dialog</Project>
    </Res>
  </ItemGroup>
  <Target Name="Main">
    <Message Text="$(destination)"/>
    <CallTarget Targets="CompileResources" />
    <CallTarget Targets="BuildSatelliteAssemblies" />
    <CallTarget Targets="CopyToFolder" Condition="$(destination)!=''"/>
    <CallTarget Targets="CleanUp" />
  </Target>
  <Target Name="CompileResources">
    <GenerateResource Sources="@(Res)" PublicClass="true" >
      <Output ItemName="Resources" TaskParameter="OutputResources"/>
    </GenerateResource>
  </Target>
  <Target Name="BuildSatelliteAssemblies" DependsOnTargets="CompileResources">
    <MakeDir Directories="%(Res.Culture)"/>
    <AL OutputAssembly="%(Culture)\%(Project).resources.dll"
        Version="0.0.0.0"
        Culture="%(Culture)"
        ProductName="%(Project)"
        Title="%(Project)"
        EmbedResources="@(Resources)"/>
  </Target>
  <Target Name="CopyToFolder" DependsOnTargets="BuildSatelliteAssemblies">
    <MakeDir Directories="$(destination)\%(Res.Culture)"/>
    <CreateItem Include="%(Res.Culture)\*.dll" AdditionalMetadata="Culture=%(Res.Culture)">
      <Output ItemName="SatelliteAssemblies" TaskParameter="Include"/>
    </CreateItem>
    <Copy DestinationFolder="$(destination)\%(Culture)" 
          SourceFiles="@(SatelliteAssemblies)" />
  </Target>
  <Target Name="CleanUp">
    <Delete Files="@(Resources)"/>
  </Target>
</Project>

The satellite assemblies seem to compile and embed correctly however when I place them with my application, they are not recognized and it defaults back to the default culture resources. If I build th开发者_JAVA百科e project with Visual Studio and use the assemblies it creates with that, they load fine.

I must be missing something in causing the application to recognize my externally built assemblies. They are all named the same and the sizes are nearly the same.


In the AL target, you can set an internal namespace to be used by each resource file in the assembly. Setting the correct namespace allowed the application to correctly find the resources in the assemblies.

0

精彩评论

暂无评论...
验证码 换一张
取 消