简体   繁体   中英

C# application not recognizing satellite resource assemblies

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 the 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM