2014-01-29 48 views
0

我有一个正在使用typecript插件与GruntJS一起构建的打字稿项目。我也有一个Visual Studio项目,我希望能够从中调用构建过程。从MSBuild运行Grunt Typescript

我在做这个是添加<Exec>任务,在Visual Studio中BeforeBuild目标的第一次尝试,与<Exec>任务配置是这样的:

<Exec Command="grunt --no-color typescript" />

这个运行构建精细,但是,当错误是从Grunt输出的,并且它们在VS中填充错误列表,文件名被错误地列为EXEC。

看着Exec Documentation我看到CustomErrorRegularExpression是该命令的一个参数,但我无法完全理解如何使用它来解决我的问题。

我搞砸了一下,并设法将报告的文件名更改为我的.jsproj文件,这也是不正确的。看着this post我试图形成自己的正则表达式:

<Exec CustomErrorRegularExpression="\.ts\([0-9]+,[0-9]+\):(.*)" Command="grunt --no-color typescript" IgnoreExitCode="true" />

没有人有使用这个参数,这个命令来实现这种事情的经验吗?我想可能是问题的一部分是咕噜打印两行错误?

回答

1

您对仅处理单行消息的Exec任务是正确的。此外,它还使用Regex.IsMatch来评估错误/警告条件,而不使用模式的捕获组。

我无法找到通过MSBuild解决此问题的方法,但纠正问题的更改很容易直接在grunt任务中完成。

我正在使用来自:https://www.npmjs.org/package/grunt-typescript的grunt-typingcript任务。

有3个微不足道的变化,使这项工作。

1)更换附近的tasks/typescript.js顶部的输出实用方法:

/* Remove the >> markers and extra spacing from the output */ 
function writeError(str) { 
    console.log(str.trim().red); 
} 

function writeInfo(str) { 
    console.log(str.trim().cyan); 
} 

2)更换Compiler.prototype.addDiagnostic写在同一行上的文件和错误数据:

Compiler.prototype.addDiagnostic = function (diagnostic) { 
    var diagnosticInfo = diagnostic.info(); 
    if (diagnosticInfo.category === 1) 
    this.hasErrors = true; 

    var message = " "; 
    if (diagnostic.fileName()) { 
    message = diagnostic.fileName() + 
     "(" + (diagnostic.line() + 1) + "," + (diagnostic.character() + 1) + "): "; 
    } 

    this.ioHost.stderr.Write(message + diagnostic.message()); 
}; 

完成这些更改后,您不再需要在Exec任务上设置CustomErrorRegularExpression,并且构建输出应显示错误文本包括带有行和列信息的正确源文件。

+0

不错!我没有想到修改咕噜任务本身。 – phosphoer