简体   繁体   English

从Gulp调用NuGet.exe时出现EBUSY错误

[英]EBUSY error when invoking NuGet.exe from Gulp

I'm using Gulp to build a large .NET solution which uses lots of NuGet packages. 我正在使用Gulp构建大型的.NET解决方案,该解决方案使用了很多NuGet包。 This has been working well for the past six months using gulp-nuget-restore to fetch the packages before compiling. 在过去的六个月中,使用gulp-nuget-restore在编译前获取软件包的效果一直很好。

However we recently acquired an internal NuGet server, and when I amended the build script to use this it started failing to find System.Core (even though all the other packages from nuget.org still worked). 但是,我们最近购买了一个内部NuGet服务器,当我修改了构建脚本以使用它时,它开始无法找到System.Core (即使nuget.org中的所有其他软件包仍然可以使用)。 I suspect that the culprit is an obsolete version of nuget.exe which is bundled with the gulp-nuget-restore package; 我怀疑罪魁祸首是与gulp-nuget-restore软件包捆绑在一起的nuget.exe的过时版本; the build works again if I manually overwrite it with a newer version. 如果我手动用较新的版本覆盖它,则该构建再次起作用。

So, I'm now trying to get the Gulp script to download the latest version of nuget.exe and use that for the package restore (this time by means of the gulp-nuget NPM package). 因此,我现在正尝试获取Gulp脚本以下载最新版本的nuget.exe,并将其用于软件包还原(这次是通过gulp-nuget NPM软件包)。 Strangely, this works perfectly on my machine but fails on the TeamCity build server. 奇怪的是,这在我的机器上完美运行,但在TeamCity构建服务器上却失败。

Here is the relevant part of my gulpfile.js : 这是我的gulpfile.js的相关部分:

const gulp = require("gulp"),
    fs = require("fs"),
    nuget = require("gulp-nuget"),
    download = require("gulp-download-stream");

const nugetExePath = "./nuget.exe";

gulp.task("download-nuget", done => {
    if (fs.existsSync(nugetExePath)) {
        return done();
    }

    return download(
        {
            file: "nuget.exe",
            url: "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
        })
        .pipe(gulp.dest("."));
});

gulp.task("nuget-restore",
    ["download-nuget"],
    () => gulp.src("./mysolution.sln")
        .pipe(nuget.restore({
            nuget: nugetExePath,
            source: "http://our-internal-proget-server/nuget/Default/"
        })));

And the TeamCity build log: 而TeamCity构建日志:

[17:14:41][Step 2/2] Executing D:\TeamCity\buildAgent3\work\88991897ccf08f65\node_modules\.bin\gulp.cmd via wrapping shell script
[17:14:41][Step 2/2] Starting: cmd /c D:\TeamCity\buildAgent3\work\88991897ccf08f65\node_modules\.bin\gulp.cmd --no-color --teamcity.properties.all=D:\TeamCity\buildAgent3\temp\agentTmp\teamcity9135120293826835528.json     --teamcity.properties=D:\TeamCity\buildAgent3\temp\agentTmp\teamcity7511878459063399775.json --configuration Release --enableteamcity --buildnumber 1299
[17:14:41][Step 2/2] in directory: D:\TeamCity\buildAgent3\work\88991897ccf08f65
[17:14:44][Step 2/2] [17:14:44] Using gulpfile D:\TeamCity\buildAgent3\work\88991897ccf08f65\gulpfile.js
[17:14:44][Step 2/2] [17:14:44] Starting 'clean'...
[17:14:44][Step 2/2] [17:14:44] Starting 'set-build-number'...
[17:14:44][Step 2/2] [17:14:44] Starting 'download-nuget'...
[17:14:44][Step 2/2] [17:14:44] Downloading https://dist.nuget.org/win-x86-commandline/latest/nuget.exe...
[17:14:44][Step 2/2] [17:14:44] Finished 'clean' after 117 ms
[17:14:45][Step 2/2] [17:14:45] Updating assembly info file 'D:\TeamCity\buildAgent3\work\88991897ccf08f65\SharedAssemblyInfo.cs'...
[17:14:45][Step 2/2] [17:14:45]     Setting attribute 'AssemblyVersion' to '1.0.*.1299'.
[17:14:45][Step 2/2] [17:14:45]     Setting attribute 'AssemblyVersion' to '1.3.9.1299'.
[17:14:45][Step 2/2] [17:14:45]     Setting attribute 'AssemblyFileVersion' to '1.3.9.1299'.
[17:14:46][Step 2/2] [17:14:46] Finished 'set-build-number' after 1.67 s
[17:14:48][Step 2/2] [17:14:48] Downloaded https://dist.nuget.org/win-x86-commandline/latest/nuget.exe after 3.98 s
[17:14:48][Step 2/2] [17:14:48] Finished 'download-nuget' after 4.01 s
[17:14:48][Step 2/2] [17:14:48] Starting 'nuget-restore'...
[17:14:48][Step 2/2] [17:14:48] 'nuget-restore' errored after 5.17 ms
[17:14:48][Step 2/2] [17:14:48] Error: spawnSync ./nuget.exe EBUSY
[17:14:48][Step 2/2]     at exports._errnoException (util.js:1026:11)
[17:14:48][Step 2/2]     at spawnSync (child_process.js:461:20)
[17:14:48][Step 2/2]     at execFileSync (child_process.js:498:13)
[17:14:48][Step 2/2]     at Gulp.gulp.task (D:\TeamCity\buildAgent3\work\88991897ccf08f65\gulpfile.js:109:9)
[17:14:48][Step 2/2]     at module.exports (D:\TeamCity\buildAgent3\work\88991897ccf08f65\node_modules\orchestrator\lib\runTask.js:34:7)
[17:14:48][Step 2/2]     at Gulp.Orchestrator._runTask (D:\TeamCity\buildAgent3\work\88991897ccf08f65\node_modules\orchestrator\index.js:273:3)
[17:14:48][Step 2/2]     at Gulp.Orchestrator._runStep (D:\TeamCity\buildAgent3\work\88991897ccf08f65\node_modules\orchestrator\index.js:214:10)
[17:14:48][Step 2/2]     at D:\TeamCity\buildAgent3\work\88991897ccf08f65\node_modules\orchestrator\index.js:279:18
[17:14:48][Step 2/2]     at finish (D:\TeamCity\buildAgent3\work\88991897ccf08f65\node_modules\orchestrator\lib\runTask.js:21:8)
[17:14:48][Step 2/2]     at D:\TeamCity\buildAgent3\work\88991897ccf08f65\node_modules\orchestrator\lib\runTask.js:52:4
[17:14:48][Step 2/2] Process exited with code 1

Does the "Error: spawnSync ./nuget.exe EBUSY" imply that something still has a lock on the nuget.exe file, even though the download has supposedly finished? “错误:spawnSync ./nuget.exe EBUSY”是否暗示nuget.exe文件仍然有锁,即使据说下载已完成?

Thanks in advance for any suggestions about how to begin troubleshooting this. 在此先感谢您提供有关如何开始对此进行故障排除的建议。

It's a horrible hack, but the error goes away if I introduce a 1-second time delay after finishing the download of nuget.exe: 这是一个可怕的骇客,但是如果我在下载完nuget.exe之后引入了1秒的时间延迟,该错误就会消失:

const wait = require("gulp-wait");

gulp.task("download-nuget", done => {
    if (fs.existsSync(nugetExePath)) {
        return done();
    }

    return download(
        {
            file: "nuget.exe",
            url: "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
        })
        .pipe(gulp.dest("."))
        .pipe(wait(1000)); // Workaround for EBUSY error on TeamCity server.
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM