ResourceManager资源名称参数配置问题咨询(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)
- Set Build Action to
- Open your
.csprojfile 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
.gitignoreor 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

