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

.net 从Gulp调用NuGet.exe时出现EBUSY错误,.net,gulp,nuget,.net,Gulp,Nuget,我正在使用Gulp构建一个大型的.NET解决方案,它使用了大量的NuGet包。在过去的六个月里,它一直运行良好,使用在编译之前获取包 然而,我们最近获得了一个内部NuGet服务器,当我修改构建脚本以使用它时,它开始无法找到System.Core(即使NuGet.org的所有其他包仍然有效)。我怀疑罪魁祸首是与gulp nuget restore包捆绑在一起的过时版本的nuget.exe;如果我手动用更新的版本覆盖它,构建将再次工作 因此,我现在正试图让Gulp脚本下载最新版本的nuget.exe

我正在使用Gulp构建一个大型的.NET解决方案,它使用了大量的NuGet包。在过去的六个月里,它一直运行良好,使用在编译之前获取包

然而,我们最近获得了一个内部NuGet服务器,当我修改构建脚本以使用它时,它开始无法找到
System.Core
(即使NuGet.org的所有其他包仍然有效)。我怀疑罪魁祸首是与gulp nuget restore包捆绑在一起的过时版本的nuget.exe;如果我手动用更新的版本覆盖它,构建将再次工作

因此,我现在正试图让Gulp脚本下载最新版本的nuget.exe,并将其用于包还原(这次是通过NPM包)。奇怪的是,这在我的机器上运行良好,但在TeamCity构建服务器上失败

下面是我的
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/"
        })));
以及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
“Error:spawnSync./nuget.exe EBUSY”是否意味着即使下载已经完成,某些东西仍然锁定了
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.
});