简体   繁体   English

C#应用程序无法识别卫星资源程序集

[英]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. 由于我们的应用程序中.resx文件数量过多,我创建了以下MSBuild脚本,以将所有语言.resx文件编译为.resource,然后将其嵌入到附属资源程序集中。

    <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. 如果我使用Visual Studio构建项目并使用由此创建的程序集,则它们会很好地加载。

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. 在AL目标中,可以设置程序集中每个资源文件要使用的内部名称空间。 Setting the correct namespace allowed the application to correctly find the resources in the assemblies. 设置正确的名称空间允许应用程序正确地在程序集中查找资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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