TL;DR:使用Visual 2015的MSBuild可以使用直接方法而不是干扰系统设置来更改命令行中MSBuild的消息语言吗?又是如何做到的?
我们有一个来自"way back当时“的问题,它本质上是一个复制,但是IMHO的答案表明这个问题需要改进。
我需要为VS2015和up工作,所以我不太关心旧版本。
下面是一些事实:
MSBuild.exe
)在德语系统上输出英语消息!devenv.exe
能够驱动MSBuild.exe
使用不同的语言。
即:
c:\temp\TestApp>msbuild TestApp.sln /t:rebuild /v:normal
Microsoft (R)-Buildmodul, Version 14.0.25420.1
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.
Die Projekte in dieser Projektmappe werden nacheinander erstellt. Um eine parallele Erstellung zu ermöglichen, müssen Sie den Schalter "/m"
hinzufügen.
Der Buildvorgang wurde am 18.10.2016 11:06:33 gestartet.
Projekt "c:\temp\TestApp\TestApp.sln" auf Knoten "1", rebuild Ziel(e).
ValidateSolutionConfiguration:
Die Projektmappenkonfiguration "Debug|X64" wird erstellt.
Das Projekt "c:\temp\TestApp\TestApp.sln" (1) erstellt "c:\temp\TestApp\TestApp\TestApp.csproj" (2) auf Knoten "1", Rebuild Ziel(e).
CoreClean:
Die Datei "C:\temp\TestApp\TestApp\bin\x64\Debug\TestApp.exe.config" wird gelöscht.
...
GenerateBindingRedirects:
Keine vorgeschlagenen BindingRedirect-Einträge von ResolveAssemblyReferences.
GenerateTargetFrameworkMonikerAttribute:
Das Ziel "GenerateTargetFrameworkMonikerAttribute" wird übersprungen, da alle Ausgabedateien hinsichtlich der Eingabedateien aktuell sind.
CoreCompile:
...
来自devenv
c:\temp\TestApp>devenv.com /Rebuild "Debug|x64" TestApp.sln
Microsoft Visual Studio 2015 Version 14.0.25420.1.
Copyright (C) Microsoft Corp. All rights reserved.
1>------ Rebuild All started: Project: TestApp, Configuration: Debug x64 ------
1>Build started 18.10.2016 11:10:27.
1>CoreClean:
1> Deleting file "C:\temp\TestApp\TestApp\bin\x64\Debug\TestApp.exe.config".
...
1>CoreCompile:
...
很明显,devenv在这里驱动输出,但是实际的msbuild消息是相同的,devenv将调用MSBuild.exe作为实际的子进程。
我已经检查了Process :被调用的MSBuild.exe没有任何指示正在使用的项目的命令行参数,也没有任何明显的环境变量集。因此,德文夫似乎在“告诉”MSBBuild以其他方式使用英语作为语言。
边注MSBuild是从VS调用的,如下所示:C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe /nologo /nodemode:1 /nodeReuse:true
那么,我如何告诉MSBuild.exe
它应该输出英语呢?我对任何包装方法或一些powershell魔术(虽然这似乎不太可能)都没意见,但我不喜欢为此依赖机器/用户区域设置。
而且,我发现MSDN线程的答案是-- 8年前-- VS可以做到这一点,因为它设置了UI文化--但是如果devenv能够做到这一点,因为它被调用了,虽然我可能也可以:我只是不知道怎么做。
发布于 2016-12-19 14:15:24
我最终得到了下面的解决方案。不知道代码是否绝对正确(我不是.NET开发人员),但它运行msbuild时设置了"en-us“区域设置。
class Program : MarshalByRefObject
{
static void Main(string[] args)
{
var newDomain = AppDomain.CreateDomain("enUSDomain");
Program newProgram = (Program)newDomain.CreateInstanceAndUnwrap(
typeof(Program).Assembly.FullName,
typeof(Program).FullName);
newProgram.Execute(args);
}
public void Execute(string[] args)
{
System.Globalization.CultureInfo.DefaultThreadCurrentUICulture =
new System.Globalization.CultureInfo("en-US");
byte[] bytes = File.ReadAllBytes("C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\MSBuild.exe");
Assembly assembly = Assembly.Load(bytes);
MethodInfo main = assembly.EntryPoint;
main.Invoke(null, new object[] { });
}
}
https://stackoverflow.com/questions/40104342
复制相似问题