gulp task runner msbuild fails, but works in cmd - msbuild

I have a project where Gulp task runner is setup. Everything works perfectly fine in VS2015, but when I upgraded to VS2017 MSBuild started to fail.
The funny thing is, that if I copy out the command line that apparently fails and paste it into the cmd, then it works perfectly fine.
I get the following error:
[09:47:27] Building project: ..\DFS.Client\DFS.Client.csproj
[09:47:27] Using automatic maxcpucount
[09:47:27] Building project: 1 item
[09:47:27] { Error: Command failed: "C:\Program Files
(x86)\MSBuild\14.0\Bin\MSBuild.exe"
"C:\solutions\dfs\code\DFS.Client\DFS.Client.csproj" "/target:Clean;Build"
/verbosity:minimal /toolsversion:14.0 /nologo /maxcpucount
/property:Configuration="Debug" /property:DeployOnBuild="true"
/property:DeployDefaultTarget="WebPublish"
/property:WebPublishMethod="FileSystem"
/property:DeleteExistingFiles="false"
/property:publishUrl="C:\inetpub\wwwroot\dfsdev\Website"
/property:_FindDependencies="true"
at ChildProcess.exithandler (child_process.js:204:12)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:891:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
killed: false,
code: 1,
signal: null,
cmd: '"C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\MSBuild.exe"
"C:\\solutions\\dfs\\code\\DFS.Client\\DFS.Client.csproj"
"/target:Clean;Build" /verbosity:minimal /toolsversion:14.0 /nologo
/maxcpucount /property:Configuration="Debug" /property:DeployOnBuild="true"
/property:DeployDefaultTarget="WebPublish"
/property:WebPublishMethod="FileSystem"
/property:DeleteExistingFiles="false"
/property:publishUrl="C:\\inetpub\\wwwroot\\dfsdev\\Website"
/property:_FindDependencies="true"' }
[09:47:27] Build failed!
If I copy the command line that is stated as failing and run it in CMD it works. I have tried the following fix without any luck.
The gulp task that fails looks like this:
var publishProjects = function (location, dest) {
dest = dest || config.websiteRoot;
var targets = ["Build"];
if (config.runCleanBuilds) {
targets = ["Clean", "Build"];
}
console.log("publish to " + dest + " folder");
return gulp.src([location + "/**/*.csproj"])
.pipe(foreach(function (stream, file) {
return stream
.pipe(debug({ title: "Building project:" }))
.pipe(msbuild({
targets: targets,
configuration: config.buildConfiguration,
logCommand: false,
verbosity: "minimal",
maxcpucount: 0,
toolsVersion: 14.0,
properties: {
DeployOnBuild: "true",
DeployDefaultTarget: "WebPublish",
WebPublishMethod: "FileSystem",
DeleteExistingFiles: "false",
publishUrl: dest,
_FindDependencies: "true"
}
}));
}));
};
Help would be appreciated as I would really like to use VS2017 rather than 2015.

Tools version 14.0 is for VS2015, tools version 15.0 is for VS2017. There is some other config you may need to change to enable it as well. Hope that helps.

Related

Jenkins pipeline executing msbuild.exe (2019) build.xml - The batch file cannot be found

pipeline {
agent { label 'Apps' }'''
environment {
MSBUILD_4_PATH = "c:\\WINDOWS\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild"
MSBUILD_2019_PATH = "c:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\MSBuild\\Current\\Bin\\MSBuild.exe"
GLOBAL_SETTINGS = "\\PATH\\TO\\msbuild_settings"
BUILD_TYPE = "Dev"
// ------
}
stage('Build Infra - Release and Test') {
steps {
dir("${env.WORKSPACE}/${BRANCH_NAME}/Infra/Build"){
bat '''
set DevEnvDir="c:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\"
"%MSBUILD_2019_PATH%" Build.xml /p:GlobalSettings=%GLOBAL_SETTINGS%;BUILD_TYPE=%BUILD_TYPE%;SC=GIT;MSBuildCommunityTasksPath="C:\\Program Files (x86)\\MSBuild\\MSBuildCommunityTasks";ExtensionTasksPath="C:\\\\Program Files (x86)\\\\MSBuild\\\\ExtensionPack\\\\4.0\\\\" /t:ReleaseAndTest
'''
}
}
}
Please help, cant find root cause of the problem
Log finished with:
375 Warning(s)
0 Error(s)
Time Elapsed 00:04:54.35
The batch file cannot be found.
Cant realize if the problem is with Jenkins pipeline or MsBuild itself
stage never finished... stack
Tried many different options and still stack

Cannot run vscode extension starter project tests twice in a row on macos

I am implementing a VSCode extension and I have set up the project following this link.
It creates a starter project and with it a src/test/runTest.ts:
import * as path from 'path';
import { runTests } from '#vscode/test-electron';
async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
// The path to test runner
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index');
// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
}
main();
and a package.json:
{
"compile": "tsc -p ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"
}
I cannot run
npm test
twice in a row.
The first time, everything goes well, and it looks like it is downloading VSCode in the folder .vscode-test.
Downloading VS Code 1.65.2 from https://update.code.visualstudio.com/1.65.2/darwin/stable
Downloading VS Code [==============================] 100%Downloaded VS Code 1.65.2 into /my-path/my-project/.vscode-test/vscode-darwin-1.65.2
However, I get a warning:
WARNING: IPC handle "/my-path/my-project/.vscode-test/user-data/1.65.2-main.sock" is longer than 103 chars, try a shorter --user-data-dir
When I run the tests a second time, if fails:
Found existing install in /my-path/my-project/.vscode-test/vscode-darwin-1.65.2. Skipping download
WARNING: IPC handle "/my-path/my-project/.vscode-test/user-data/1.65.2-main.sock" is longer than 103 chars, try a shorter --user-data-dir
[main 2022-03-29T14:44:22.271Z] Could not delete obsolete instance handle Error: ENOENT: no such file or directory, unlink '/my-path/my-project/.vscode-test/user-data/1.65.2-main.sock'
at unlinkSync (original-fs.js:1210:3)
at ne.claimInstance (/my-path/my-project/.vscode-test/vscode-darwin-1.65.2/Visual Studio Code.app/Contents/Resources/app/out/vs/code/electron-main/main.js:77:5083)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async /my-path/my-project/.vscode-test/vscode-darwin-1.65.2/Visual Studio Code.app/Contents/Resources/app/out/vs/code/electron-main/main.js:77:2282
at async ne.startup (/my-path/my-project/.vscode-test/vscode-darwin-1.65.2/Visual Studio Code.app/Contents/Resources/app/out/vs/code/electron-main/main.js:77:2151) {
errno: -2,
syscall: 'unlink',
code: 'ENOENT',
path: '/my-path/my-project/.vscode-test/user-data/1.65.2-main.sock'
}
[main 2022-03-29T14:44:22.274Z] Error: ENOENT: no such file or directory, unlink '/my-path/my-project/.vscode-test/user-data/1.65.2-main.sock'
at unlinkSync (original-fs.js:1210:3)
at ne.claimInstance (/my-path/my-project/.vscode-test/vscode-darwin-1.65.2/Visual Studio Code.app/Contents/Resources/app/out/vs/code/electron-main/main.js:77:5083)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async /my-path/my-project/.vscode-test/vscode-darwin-1.65.2/Visual Studio Code.app/Contents/Resources/app/out/vs/code/electron-main/main.js:77:2282
at async ne.startup (/my-path/my-project/.vscode-test/vscode-darwin-1.65.2/Visual Studio Code.app/Contents/Resources/app/out/vs/code/electron-main/main.js:77:2151)
Exit code: 1
Failed to run tests
But it works fine if I delete the folder .vscode-test.
What is happening and what can I do?
try to make your work directory shorter
or
use the os temporary directory
for example:
await runTests({
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: ['--user-data-dir', `${os.tmpdir()}`]
});

Gulp task to web deploy from Visual Studio

I have not found a concrete example on how to do the publishing via a Gulp Task. Anyone has an idea?
This is how i'm trying at the moment.
gulp.task("Deploy-To-Azure", function() {
var targets = ["Build"];
console.log("Publishing to Azure");
return gulp.src(["./src/Feature/Accounts/code"])
.pipe(foreach(function (stream, file) {
return stream
.pipe(debug({ title: "Building project:" }))
.pipe(msbuild({
targets: targets,
configuration: "Azure",
logCommand: false,
verbosity: "verbose",
stdout: true,
errorOnFail: true,
maxcpucount: 0,
toolsVersion: 14.0,
properties: {
DeployOnBuild: "true",
DeployDefaultTarget: "Web Deploy",
WebPublishMethod: "FileSystem",
DeleteExistingFiles: "false",
_FindDependencies: "false",
Configuration: "Release"
}
}))
.pipe(debug({title: "Finished building project"}));
}));
});
But it looks like the project is built but not deployed. I think my properties are not complete. Any ideas are appreciated. Thank you
I attempted to use those same MSBuild properties from the commandline and received the following error:
>c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild /p:DeployOnBuild=true /p:WebPub
lishMethod=FileSystem /p:DeleteExistingFiles=false /p:DeployDefaultTarget="Web Deploy"
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.P
ublishing.targets(4449,11): error MSB4057: The target "Web Deploy" does not exi
st in the project. [c:\users\me\documents\visual studio 2015\projects\w
ebapplication12\WebApplication12.csproj]
Unless you've created a custom MSBuild Target named "Web Deploy". This won't work.
When I remove the /p:DeployDefaultTarget="Web Deploy" property a WebDeploy package is created in the /obj/[configuration]/Package folder.
Try DeployDefaultTarget: "WebPublish"

Error publishing ASP.NET Core project

I have an ASP.NET Core RC1 project that no longer publishes correctly (see publish trace output, below). The gulp min task in the prepublish script defined in project.json is causing the error. If I remove it, the project publishes correctly, but without minifying the js and css files.
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
}
I have added another Web Project to the solution, and that publishes without error, so I think that eliminates environmental issues. However, I can't see anything substantially different between the test project and the one that fails.
I have also deleted the node_modules folder in the failing project to force Visual Studio to download all the npm packages again.
Finally I ran the dnu publish command in the trace below from the VS command prompt and that also failed.
Can anyone tell me what the problem is from the error trace below, please?
Connecting to C:\svn\Client Applications\yyy\xxx\src\xxxWeb\..\..\artifacts\bin\xxx.Web\Release\PublishOutput...
Environment variables:
Path=.\node_modules\.bin;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External;%PATH%;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\git
C:\Users\ptayl_000\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-final\bin\dnu.cmd publish "C:\svn\Client Applications\yyy\xxx\src\xxxWeb" --out "C:\Users\ptayl_000\AppData\Local\Temp\PublishTemp\xxx.Web104" --configuration Release --no-source --runtime dnx-clr-win-x86.1.0.0-rc1-final --wwwroot "wwwroot" --wwwroot-out "wwwroot" --iis-command "web" --quiet
Microsoft .NET Development Utility Clr-x86-1.0.0-rc1-16202
Executing script 'prepublish' in project.json
v0.10.31
npm WARN package.json ASP.NET#0.0.0 No description
npm WARN package.json ASP.NET#0.0.0 No repository field.
npm WARN package.json ASP.NET#0.0.0 No README data
[07:36:31] Using gulpfile C:\svn\Client Applications\yyy\xxx\src\xxxWeb\gulpfile.js
[07:36:31] Starting 'clean:js'...
[07:36:31] Starting 'clean:css'...
[07:36:31] Finished 'clean:js' after 1.68 ms
[07:36:31] Finished 'clean:css' after 1.99 ms
[07:36:31] Starting 'clean'...
[07:36:31] Finished 'clean' after 9.03 μs
[07:36:32] Using gulpfile C:\svn\Client Applications\yyy\xxx\src\xxxWeb\gulpfile.js
[07:36:32] Starting 'min:js'...
[07:36:32] Starting 'min:css'...
[07:36:32] Finished 'min:css' after 61 ms
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(152,5): Error : events.js:72
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(152,5): Error : throw er; // Unhandled 'error' event
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(152,5): Error : ^
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(152,5): Error : Error
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(152,5): Error : at new JS_Parse_Error (C:\svn\Client Applications\yyy\xxx\src\xxxWeb\node_modules\gulp-uglify\node_modules\uglify-js\lib\parse.js:196:18)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(152,5): Error : at js_error (C:\svn\Client Applications\yyy\xxx\src\xxxWeb\node_modules\gulp-uglify\node_modules\uglify-js\lib\parse.js:204:11)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(152,5): Error : at croak (C:\svn\Client Applications\yyy\xxx\src\xxxWeb\node_modules\gulp-uglify\node_modules\uglify-js\lib\parse.js:675:9)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(152,5): Error : at token_error (C:\svn\Client Applications\yyy\xxx\src\xxxWeb\node_modules\gulp-uglify\node_modules\uglify-js\lib\parse.js:683:9)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(152,5): Error : at expect_token (C:\svn\Client Applications\yyy\xxx\src\xxxWeb\node_modules\gulp-uglify\node_modules\uglify-js\lib\parse.js:696:9)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(152,5): Error : at expect (C:\svn\Client Applications\yyy\xxx\src\xxxWeb\node_modules\gulp-uglify\node_modules\uglify-js\lib\parse.js:699:36)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(152,5): Error : at C:\svn\Client Applications\yyy\xxx\src\xxxWeb\node_modules\gulp-uglify\node_modules\uglify-js\lib\parse.js:1252:13
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(152,5): Error : at C:\svn\Client Applications\yyy\xxx\src\xxxWeb\node_modules\gulp-uglify\node_modules\uglify-js\lib\parse.js:722:24
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(152,5): Error : at expr_atom (C:\svn\Client Applications\yyy\xxx\src\xxxWeb\node_modules\gulp-uglify\node_modules\uglify-js\lib\parse.js:1182:35)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(152,5): Error : at maybe_unary (C:\svn\Client Applications\yyy\xxx\src\xxxWeb\node_modules\gulp-uglify\node_modules\uglify-js\lib\parse.js:1358:19)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(152,5): Error : The 'prepublish' script failed with status code 8.
2>Publish failed due to build errors. Check the error list for more details.
Update
The gulp min task contains the following code (from gulp.js):
gulp.task("min:js", function () {
return gulp.src([paths.js, "!" + paths.minJs], { base: "." })
.pipe(concat(paths.concatJsDest))
.pipe(uglify())
.pipe(gulp.dest("."));
});
Update2: event.js
var rx = require("rx");
function normalizeKeypressEvents(args) {
return { value: args[0], key: args[1] };
}
module.exports = function(rl) {
return {
line: rx.Observable.fromEvent(rl, "line"),
keypress: rx.Observable.fromEvent(rl, "keypress", normalizeKeypressEvents),
normalizedUpKey: rx.Observable.fromEvent(rl, "keypress", normalizeKeypressEvents).filter(function (e) {
return e.key && (e.key.name === "up" || e.key.name === "k");
}).share(),
normalizedDownKey: rx.Observable.fromEvent(rl, "keypress", normalizeKeypressEvents).filter(function (e) {
return e.key && (e.key.name === "down" || e.key.name === "j");
}).share(),
numberKey: rx.Observable.fromEvent(rl, "keypress", normalizeKeypressEvents).filter(function (e) {
return e.value && "123456789".indexOf(e.value) >= 0;
}).map(function(e) {
return Number(e.value);
}).share(),
spaceKey: rx.Observable.fromEvent(rl, "keypress", normalizeKeypressEvents).filter(function (e) {
return e.key && e.key.name === "space";
}).share(),
};
};
Turned out that it was a piece of application javascript that was causing the "gulp min" task to fail. The culprit was the following seemingly innocuous piece of code:
$http.get(uri, { params: { config } }).then(function (data) {
return data;
});
I still can't see any problem with it, but as the code had become redundant, I removed it and solved the problem that way.
I was getting the same issues (even on the same line numbers). Paul's own answer gave me a clue to look carefully at my own .js
I commented out most of the file and then progressively uncommented blocks of code until the errors came back.
And the offending code?
This line that uses a template string was the problem:
rtUl.insertAdjacentHTML("beforeend", `<li>${el.toString()}</li>`);
Changing it back to a simple concatenation worked:
rtUl.insertAdjacentHTML("beforeend", "<li>" + el.toString() + "</li>");
It seems that uglify can't read string templates (yet).

Gulp issue when copying over fonts

Every now and then, when I do a gulp build, I would get this error:
Error: EEXIST, mkdir 'Users/username/Desktop/Project/dist/fonts' at Error (native)
It doesn't happen on every build though. My gulp code to copy over fonts is:
gulp.src(paths.fonts { cwd: bases.app })
.pipe(flatten()) // using gulp-flatten
.pipe(gulp.dest(bases.dist + 'fonts/'));
Is there a way for me to fix this issue?
I believe you have to delete the old fonts/ folder first.
Use something like Gulp del:
I also like gulp-util for gulp console logs:
gulp.task('removeFonts', function(cb) {
del([bases.dist + 'fonts/'], cb);
gutil.log(gutil.colors.magenta('Fonts folder removed');
});
Then call your mkdir build.