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

如何获取CS-Script编译时的英文警告与错误信息

How to Get English Error/Warning Messages in CS-Script Runtime Compilation

Got it, let's sort out how to switch those German error and warning messages to English when using CS-Script for runtime compilation. Here are two reliable approaches:

1. Set the VSLANG Environment Variable

The .NET compiler (csc.exe/Roslyn) uses the VSLANG environment variable to determine the language for output messages. Setting it to 1033 (the locale ID for English - US) will force English output.

You can set this either globally for your entire application or right before calling the CS-Script compilation:

// Set the environment variable before compiling
Environment.SetEnvironmentVariable("VSLANG", "1033");

// Your existing compilation code
var eval = CSScript.Evaluator;
var assembly = eval.CompileCode(code);

// Check for errors/warnings
if (CSScript.CompilingHistory.Any()) {
    foreach (var err in CSScript.CompilingHistory.Last().Value.Result.Errors.Cast<CompilerError>()) {
        this.AddValidationResult(err, codeFile);
    }
}

Note: If you need to revert back to the original language later, save the previous value of VSLANG and restore it after compilation.

2. Pass Compiler Options Directly to CS-Script

CS-Script lets you pass custom compiler flags to the underlying .NET compiler. You can specify the culture directly via compiler options:

var eval = CSScript.Evaluator;
// Add the culture flag to force English output
eval.CompilerOptions = "/culture:en-US";

var assembly = eval.CompileCode(code);

// Your existing error checking code here...

This approach targets just the CS-Script evaluator instance, so it won't affect other parts of your application that might rely on the original locale.

Why This Works

CS-Script relies on the official .NET compiler (either csc.exe or Roslyn) under the hood. Both compilers respect the VSLANG environment variable and the /culture compiler option to determine the language of diagnostic messages. By setting either of these, you override the system's default locale for compiler output.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 10:40:24