Skip to content

Instantly share code, notes, and snippets.

@cassidydotdk
Last active January 31, 2023 15:49
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save cassidydotdk/d2c72096ee0a1b5cf1e542ee108ce024 to your computer and use it in GitHub Desktop.
Save cassidydotdk/d2c72096ee0a1b5cf1e542ee108ce024 to your computer and use it in GitHub Desktop.
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\\sc911.sc",
sitecoreLibraries: "C:\\inetpub\\wwwroot\\sc911.sc\\bin",
hostName: "http://sc911.sc",
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:DeployOnBuild=true');
overrideParams.push('/p:DeployDefaultTarget=WebPublish');
overrideParams.push('/p:WebPublishMethod=FileSystem');
overrideParams.push('/p:DeleteExistingFiles=false');
overrideParams.push('/p:publishUrl=' + config.websiteRoot);
msbuild.config('overrideParams',overrideParams);
msbuild.config('version', config.toolsVersion);
// msbuild.targets = ["Build"];
msbuild.build(); // calls (callback) when done
});
@cassidydotdk
Copy link
Author

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.

@Antonytm
Copy link

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'

@aleksandartraja
Copy link

@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