11

I am currentlly in the process of writing a Cake build script to build a number of ASP.NET MVC sites.

At the moment I am unable to see an option to pass arguments to MSBuild to produce the _PublishedWebsites folder for deployment.

I believe the arguments that I need to pass are:

/p:OutDir=$(build.stagingDirectory)
/p:DeployOnBuild=true
/p:WebPublishMethod=Package
/p:PackageAsSingleFile=true 
/p:SkipInvalidConfigurations=true 

If there is an alternative approach which produces the same output content just not in the same folder directory that would be fine.

MeanGreen
  • 3,098
  • 5
  • 37
  • 63
SouthernDev
  • 113
  • 1
  • 5

2 Answers2

22

The following example should set the correct MSBuild properties when building your website solution from Cake.

MSBuild("./src/Website.sln", new MSBuildSettings()
  .WithProperty("OutDir", "$(build.stagingDirectory)")
  .WithProperty("DeployOnBuild", "true")
  .WithProperty("WebPublishMethod", "Package")
  .WithProperty("PackageAsSingleFile", "true")
  .WithProperty("SkipInvalidConfigurations", "true"));

To set the output directory of the website, simply swap out the "$(build.stagingDirectory)" part with the path to the directory where you want the output to appear.

You can read more about the MSBuild alias in Cake here: http://cakebuild.net/api/cake.common.tools.msbuild/

Terje
  • 357
  • 2
  • 14
Patrik Svensson
  • 13,536
  • 8
  • 56
  • 77
  • What version of Cake are you using? I am getting errors for `DeployOnBuild`, `WebPublishMethod`, `PackageAsSingleFile` not existing on `MSBuildSettings`. The documentation linked above also does not list these properties. – JamesFaix May 02 '20 at 22:08
  • They are not properties on `MSBuildSettings`, they are MSBuild properties. – Patrik Svensson Jun 05 '20 at 10:18
  • I thought `WithProperty` was just a fluent way of setting properties on the starting object. Like `x.WithProperty("y", 1)` would be the same as `x.y = 1` – JamesFaix Jun 05 '20 at 13:14
1

For FileSystem publish it can be done this way:

MSBuild(/**project path**/, settings =>
    settings.SetConfiguration(/**configuration**/)
    .WithProperty("DeployTarget", "WebPublish")
    .WithProperty("DeployOnBuild", /**boolean**/)
    .WithProperty("PackageAsSingleFile", /**boolean**/)
    .WithProperty("WebPublishMethod", "FileSystem")
    .WithProperty("PublishUrl", /**url**/)
);
Thulani Chivandikwa
  • 3,402
  • 30
  • 33
  • Configuration is? – David Graham Dec 19 '18 at 16:13
  • What version of Cake are you using? I am getting errors for `DeployOnBuild`, `DeployTarget`, `WebPublishMethod`, `PackageAsSingleFile` not existing on `MSBuildSettings`. The documentation also does not list these properties. – JamesFaix May 02 '20 at 22:09