You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ResourceManager资源名称参数配置问题咨询(Azure Pipeline与本地运行不一致)

Fixing "Could not find the resource among the resources embedded in the assembly" in Azure Pipeline

First, let's break down what's happening here: your local build works perfectly with the resource name Ultrasonic.Customers.Application.Resources.AppMessage, but Azure Pipeline keeps throwing a missing resource error. This almost always comes down to differences in how resources are embedded or named between your local environment and the CI build process.

Why This Happens Locally vs. Azure

On your machine, the default build correctly embeds the base English resource (AppMessage.en.resx, your default culture) into the main assembly with the name Ultrasonic.Customers.Application.Resources.AppMessage.resources. But in Azure Pipeline, one of these key details is likely misconfigured:

  • The build action for your resx files isn't set to Embedded Resource
  • The custom tool or namespace settings aren't synced in source control
  • The CI build uses MSBuild parameters that alter resource naming rules
  • Satellite assemblies for non-default cultures (like pt-BR) aren't being generated properly

Step-by-Step Fixes

1. Replace Hardcoded Resource Name with typeof(AppMessage)

This is the most reliable fix—it eliminates manual string errors entirely. Update the ResourceManager initialization line in your AppMessage.en.Designer.cs to:

global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager(typeof(AppMessage));

The ResourceManager constructor that takes a Type automatically resolves the correct resource name based on your strongly-typed resource class, so you don't have to worry about mismatched namespaces or file paths.

2. Verify Resource File Configurations in Your Project

Ensure all resx files have the correct build settings (check these into source control so Azure uses the same config):

  • For AppMessage.en.resx and AppMessage.pt-BR.resx:
    • Set Build Action to Embedded Resource
    • Set Custom Tool to ResXFileCodeGenerator
    • Set Custom Tool Namespace to Ultrasonic.Customers.Application.Resources (matches the namespace in your Designer class)
  • Open your .csproj file to confirm the entries look like this (make sure no resx files are marked as <None>):
    <EmbeddedResource Include="Resources\AppMessage.en.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>AppMessage.en.Designer.cs</LastGenOutput>
      <CustomToolNamespace>Ultrasonic.Customers.Application.Resources</CustomToolNamespace>
    </EmbeddedResource>
    <EmbeddedResource Include="Resources\AppMessage.pt-BR.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <CustomToolNamespace>Ultrasonic.Customers.Application.Resources</CustomToolNamespace>
    </EmbeddedResource>
    

3. Check Azure Pipeline Build Parameters

  • If using a DotNet Build or MSBuild task in Azure DevOps, ensure you're not passing any parameters that modify resource embedding (like /resource: or custom resource flags).
  • Disable any "Satellite Resource Optimization" options if enabled—these can sometimes strip or rename default culture resources.
  • Confirm your pipeline is building the correct project file, and that all resx files are included in the build (no .gitignore or pipeline exclusions blocking them).

4. Validate Embedded Resources in Build Artifacts

To confirm the root cause, download the build artifact from Azure Pipeline and inspect the main assembly (Ultrasonic.Customers.Application.dll) using a tool like dnSpy or ILDasm:

  • Look for embedded resources named Ultrasonic.Customers.Application.Resources.AppMessage.resources (for the default English culture)
  • Check that satellite assemblies (like pt-BR\Ultrasonic.Customers.Application.resources.dll) exist in the output folder

Final Notes

Using typeof(AppMessage) is the most foolproof approach because it removes human error from resource name hardcoding. If you stick with the hardcoded name, make sure it exactly matches the full embedded resource name (case-sensitive!) that Azure Pipeline generates.

内容的提问来源于stack exchange,提问作者zupp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 18:57:30