2

I would like to use Cake script to automate my build and publish process. I started some tests with local publish but I was unable to make my Cake script to use publish profile that I've created in Visual Studio. Is it possible at all?

Here is my publish profile file:

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 <PropertyGroup>
  <WebPublishMethod>FileSystem</WebPublishMethod>
  <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
  <LastUsedPlatform>Any CPU</LastUsedPlatform>
  <SiteUrlToLaunchAfterPublish />
  <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
  <ExcludeApp_Data>False</ExcludeApp_Data>
  <publishUrl>C:\Users\radoslaw.stolarczyk\Desktop\CakeWebSite</publishUrl>
  <DeleteExistingFiles>True</DeleteExistingFiles>
 </PropertyGroup>
</Project>

And here are two versions of my cake script:

  1. I tried to publish my website using pubslish profile (CakeProfile.pubxml). It's not working at all the website is published to the folder inside the project folder.

    MSBuild("./CakeWebSite.sln", settings =>
    settings.WithProperty("DeployOnBuild", "true")
    .WithProperty("PublishProfile", "CakeProfile"));
    
  2. It didn't worked well so I tried to set the same properties as in publish file:

    MSBuild("./CakeWebSite.sln", new MSBuildSettings()
     .WithProperty("WebPublishMethod", "FileSystem")
     .WithProperty("LastUsedBuildConfiguration", "Debug")
     .WithProperty("LastUsedPlatform", "Any CPU")
     .WithProperty("ExcludeApp_Data", "False")
     .WithProperty("publishUrl", cakePublishPath)
     .WithProperty("OutDir", cakePublishPath)
     .WithProperty("DeleteExistingFiles", "True")
    

Second option worked better but still not sa expected. The build output from Cake script is different then from Visual Studio publish option as you can see on the picture below:

Publish outputs

Maybe it's not a big deal for example with Cake I got precompiledApp.config and with Visual studio I don't but still I would like to get the same output from both publish methods.

So my question is: Is it possible to use publish profile from Visual Studio in Cake script or to recive the same output (from Cake, and VS) and how?

1 Answers1

0

I have the configuration below that works for me. I use the project file instead of the solution.

MSBuild(prjFile, new MSBuildSettings()
  .UseToolVersion(MSBuildToolVersion.VS2017)
    .WithTarget("Package")
  .WithProperty("Configuration",configuration)
  .WithProperty("_PackageTempDir", stagingDir)
  .WithProperty("SolutionDir","../")

where configuration is:

var configuration = Argument("configuration", "Release");
Jram
  • 26
  • 3
  • Hi, Thanks for the answer. Unfortunatelly I do not have .csproj file in the project I would like to publish. What I find out because of your answer is that when using .Sln file the MSBuild do not care about the publish profile I would like to use but instead it's creating a default Debug | Any CPU configuration. – Radosław Stolarczyk Jun 25 '18 at 12:05
  • What version of Cake are you using? I do not see these properties on `MSBuildSettings` in the documentation, and it fails at runtime for me because it can't find those properties. https://cakebuild.net/api/Cake.Common.Tools.MSBuild/MSBuildSettings/ – JamesFaix May 04 '20 at 13:28