3

我在尝试使用 C# 控制台应用程序构建我的 ASP.Net 解决方案时遇到此错误:

MSBUILD:警告 MSB4056:必须在单线程单元上调用 MSBuild 引擎。当前的线程模型是“MTA”。继续,但某些任务可能无法正常运行。

这是我的代码:

Engine engine = new Engine();
engine.BinPath = @"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319";

FileLogger logger = new FileLogger();
logger.Parameters = @"logfile=C:\temp\build.log";
engine.RegisterLogger(logger);

bool success = engine.BuildProjectFile(ConfigurationSettings.AppSettings["ProjectPath"]);

engine.UnregisterAllLoggers();
if (success)
    Console.WriteLine("Build succeeded.");
else
    Console.WriteLine(@"Build failed. View C:\temp\build.log for details");
4

1 回答 1

1

Just decorate the main method with [STAThread].

That said, the only issues that could cause if you can tasks that calls into COM methods. In other words, it is generally safe to ignore it.

于 2013-03-06T06:56:57.523 回答