0

我做了一个自定义的 grunt 任务,将过滤后的文件嵌入到 Visual Studio C# 项目文件 ( *.csproj) 中。

该任务(vsembed)是我正在使用 grunt 开发的自定义构建系统的一部分。

咕噜文件.jsvsembed.js

问题是一个奇怪的问题,虽然......

TL;博士

如果我运行特定目标的任务 - 成功。如果我一次运行所有目标 - 退出时没有错误。

长版。

如果我运行指定目标的任务(因此它运行一次),它将成功完成,如下所示:

C:\StoneOS>grunt vsembed:StoneOS.Modules.Pages.views --debug --verbose
Initializing
Command-line options: --debug=1, --verbose

Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK

Registering "grunt_tasks" tasks.
Loading "vsembed.js" tasks...OK
+ vsembed, vsrembed

Registering "grunt-msbuild" local Npm module tasks.
Reading C:\StoneOS\node_modules\grunt-msbuild\package.json...OK
Parsing C:\StoneOS\node_modules\grunt-msbuild\package.json...OK
Loading "msbuild.js" tasks...OK
+ msbuild

Registering "grunt-contrib-compass" local Npm module tasks.
Reading C:\StoneOS\node_modules\grunt-contrib-compass\package.json...OK
Parsing C:\StoneOS\node_modules\grunt-contrib-compass\package.json...OK
Loading "compass.js" tasks...OK
+ compass

Registering "grunt-contrib-copy" local Npm module tasks.
Reading C:\StoneOS\node_modules\grunt-contrib-copy\package.json...OK
Parsing C:\StoneOS\node_modules\grunt-contrib-copy\package.json...OK
Loading "copy.js" tasks...OK
+ copy

Registering "grunt-contrib-clean" local Npm module tasks.
Reading C:\StoneOS\node_modules\grunt-contrib-clean\package.json...OK
Parsing C:\StoneOS\node_modules\grunt-contrib-clean\package.json...OK
Loading "clean.js" tasks...OK
+ clean
Loading "Gruntfile.js" tasks...OK
+ assets, default, development, embed, release, rembed

Running tasks: vsembed:StoneOS.Modules.Pages.views

Running "vsembed:StoneOS.Modules.Pages.views" (vsembed) task
[D] Task source: grunt_tasks\vsembed.js
Verifying property vsembed.StoneOS\.Modules\.Pages\.views exists in config...OK
File: [no files]
Options: project="C:\\StoneOS\\src\\StoneOS.Modules.Pages", directories=["views"], extensions=".cshtml"
Found embeddable files within filesystem:  [ 'views\\websocket.cshtml', 'views\\websocket\\script.cshtml' ]
Acceptable item: <EmbeddedResource Include="views\websocket.cshtml"/>
Acceptable item: <EmbeddedResource Include="views\websocket\script.cshtml"/>
Included 2 files.
Written 3861 bytes to: C:\StoneOS\src\StoneOS.Modules.Pages\StoneOS.Modules.Pages.csproj

Done, without errors.

如果我为整个团队运行任务,它有时会完成 3 个目标,有时会完成 4 个目标,有时会在完成第 4 个目标时退出。这是最新运行的输出,它在上面特定目标示例中所示的相同任务处停止,即第 4 个任务。

C:\StoneOS>grunt vsembed --debug --verbose
Initializing
Command-line options: --debug=1, --verbose

Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK

Registering "grunt_tasks" tasks.
Loading "vsembed.js" tasks...OK
+ vsembed, vsrembed

Registering "grunt-msbuild" local Npm module tasks.
Reading C:\StoneOS\node_modules\grunt-msbuild\package.json...OK
Parsing C:\StoneOS\node_modules\grunt-msbuild\package.json...OK
Loading "msbuild.js" tasks...OK
+ msbuild

Registering "grunt-contrib-compass" local Npm module tasks.
Reading C:\StoneOS\node_modules\grunt-contrib-compass\package.json...OK
Parsing C:\StoneOS\node_modules\grunt-contrib-compass\package.json...OK
Loading "compass.js" tasks...OK
+ compass

Registering "grunt-contrib-copy" local Npm module tasks.
Reading C:\StoneOS\node_modules\grunt-contrib-copy\package.json...OK
Parsing C:\StoneOS\node_modules\grunt-contrib-copy\package.json...OK
Loading "copy.js" tasks...OK
+ copy

Registering "grunt-contrib-clean" local Npm module tasks.
Reading C:\StoneOS\node_modules\grunt-contrib-clean\package.json...OK
Parsing C:\StoneOS\node_modules\grunt-contrib-clean\package.json...OK
Loading "clean.js" tasks...OK
+ clean
Loading "Gruntfile.js" tasks...OK
+ assets, default, development, embed, release, rembed

Running tasks: vsembed

Running "vsembed" task
[D] Task source: grunt_tasks\vsembed.js

Running "vsembed:StoneOS.Modules.Authentication.views" (vsembed) task
[D] Task source: grunt_tasks\vsembed.js
Verifying property vsembed.StoneOS\.Modules\.Authentication\.views exists in config...OK
File: [no files]
Options: project="C:\\StoneOS\\src\\StoneOS.Modules.Authentication", directories=["views"], extensions=".cshtml"
Found embeddable files within filesystem:  [ 'views\\login.cshtml' ]
Acceptable item: <EmbeddedResource Include="views\login.cshtml"/>
Included 1 files.
Written 4605 bytes to: C:\StoneOS\src\StoneOS.Modules.Authentication\StoneOS.Modules.Authentication.csproj

Running "vsembed:StoneOS.Modules.Installer.views" (vsembed) task
[D] Task source: grunt_tasks\vsembed.js
Verifying property vsembed.StoneOS\.Modules\.Installer\.views exists in config...OK
File: [no files]
Options: project="C:\\StoneOS\\src\\StoneOS.Modules.Installer", directories=["views"], extensions=".cshtml"
Found embeddable files within filesystem:  [ 'views\\introduction.cshtml',
  'views\\layouts\\installer.cshtml' ]
Acceptable item: <EmbeddedResource Include="views\introduction.cshtml"/>
Acceptable item: <EmbeddedResource Include="views\layouts\installer.cshtml"/>
Included 2 files.
Written 3470 bytes to: C:\StoneOS\src\StoneOS.Modules.Installer\StoneOS.Modules.Installer.csproj

Running "vsembed:StoneOS.Modules.Main.views" (vsembed) task
[D] Task source: grunt_tasks\vsembed.js
Verifying property vsembed.StoneOS\.Modules\.Main\.views exists in config...OK
File: [no files]
Options: project="C:\\StoneOS\\src\\StoneOS.Modules.Main", directories=["views"], extensions=".cshtml"
Found embeddable files within filesystem:  [ 'views\\test.cshtml',
  'views\\layouts\\logo.cshtml',
  'views\\layouts\\main.cshtml',
  'views\\errors\\403.cshtml',
  'views\\errors\\404.cshtml' ]
Acceptable item: <EmbeddedResource Include="views\test.cshtml"/>
Acceptable item: <EmbeddedResource Include="views\layouts\logo.cshtml"/>
Acceptable item: <EmbeddedResource Include="views\layouts\main.cshtml"/>
Acceptable item: <EmbeddedResource Include="views\errors\403.cshtml"/>
Acceptable item: <EmbeddedResource Include="views\errors\404.cshtml"/>
Included 5 files.
Written 7090 bytes to: C:\StoneOS\src\StoneOS.Modules.Main\StoneOS.Modules.Main.csproj

Running "vsembed:StoneOS.Modules.Pages.views" (vsembed) task
[D] Task source: grunt_tasks\vsembed.js
Verifying property vsembed.StoneOS\.Modules\.Pages\.views exists in config...OK
File: [no files]

对于“强制退出”,我的意思是,正如您在上面看到的,它以File: [no files]在详细模式下运行时的原生 grunt 功能结束。如上面这三个目标输出所示,它总是紧随其后。Options

感觉好像它是在达到超时或一些内存限制后发生的。

如果我删除一些XML基于任务,任务将完成(虽然,失去了所有目的),所以我认为问题可能出在libxmljs. 是什么让我只假设,是最后一个输出 - 甚至本grunt机输出也被切断。

运行Windows 7 x64, node v0.10.29, npm 1.4.14, grunt-cli v0.1.13, grunt v0.4.5.

我这里真的没有线索...

什么可能导致单个目标执行但多个顺序“静默失败”的问题?

4

1 回答 1

0

非常有趣的是,开始更多地调试它时,我偶然发现了node-memwatch

添加一些HeapDiff检查使我的任务能够运行,因此,它看起来与内存/GC 有关。

删除HeapDiff检查,添加手动 GC 清除global.gc();并运行grunt解决--expose-gc了问题。

可悲的是,但现在从一个简单的角度来看,grunt vsembed我必须在本地安装gruntgrunt-cli(而不是 -g),并使用node --expose-gc node_modules\grunt-cli\bin\grunt vsembed.

嗯,不管怎样,解决了。

于 2014-09-24T08:42:47.043 回答