Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Task to build and publish a .SLN file from gulp using "msbuild" instead of "gulp-msbuild". Version 16.0 for VS2019, use 15.0 for VS2017.
module.exports = function () {
var config = {
websiteRoot: "C:\\inetpub\\wwwroot\\",
sitecoreLibraries: "C:\\inetpub\\wwwroot\\\\bin",
hostName: "",
solutionName: "sc911",
buildConfiguration: "Debug",
runCleanBuilds: false,
toolsVersion: "16.0"
return config;
var _msbuild = require("msbuild");
gulp.task("Publish-Solution", function (callback) {
var msbuild = new _msbuild(callback);
msbuild.solutionName = config.solutionName;
var overrideParams = [];
overrideParams.push('/p:Configuration=' + config.buildConfiguration);
overrideParams.push('/p:publishUrl=' + config.websiteRoot);
msbuild.config('version', config.toolsVersion);
// msbuild.targets = ["Build"];; // calls (callback) when done

This comment has been minimized.

Copy link
Owner Author

@cassidydotdk cassidydotdk commented May 24, 2019

Made a minor update to how (callback) is treated. I misunderstood (or didn't fully understand) how chained NPM tasks really hook up; so the task ran asynchronous. This is now solved.


This comment has been minimized.

Copy link

@Antonytm Antonytm commented Dec 6, 2019

If you have few solution files in source folder, you will get error: 'MSBUILD : error MSB1050: Specify which project or solution file to use because the folder "..........." contains more than one project or solution file.'

You need to set sourcePath, instead of solutionName (line 7). Probably in some version it was solutionName, but not now.
msbuild.sourcePath = config.solutionName + '.sln'


This comment has been minimized.

Copy link

@aleksandartraja aleksandartraja commented Mar 30, 2020

@Antonytm, unfortunately, your suggestion didn't work for me. Do you have any suggestions or ideas about what might be wrong? I'm using gulp task in teamcity to do the build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment