0

I am trying to use Cake's built in MSBuild functionality to only build a specific Target (i.e. Compile). Using the example at: https://cakebuild.net/api/Cake.Common.Tools.MSBuild/MSBuildAliases/C240F0FB

var settings = new MSBuildSettings()
{
    Verbosity = Verbosity.Diagnostic,
    ToolVersion = MSBuildToolVersion.VS2017,
    Configuration = "Release",
    PlatformTarget = PlatformTarget.MSIL
};
settings.WithTarget("Compile");

MSBuild("./src/Cake.sln", settings);

But it seems to build all targets, where as i would like to only build a specific target, as detailed in: https://msdn.microsoft.com/en-us/library/ms171486.aspx

Ibz
  • 518
  • 1
  • 8
  • 26

1 Answers1

3

As per the documentation here:

https://cakebuild.net/api/Cake.Common.Tools.MSBuild/MSBuildSettingsExtensions/01F8DC03

The WithTarget extension method returns the same instance of the MSBuildSettings with the modifications, it doesn't interact with the current instance. As a result, where you have:

settings.WithTarget("Compile");

Is actually not doing anything. However, if you do this:

var settings = new MSBuildSettings()
{
    Verbosity = Verbosity.Diagnostic,
    ToolVersion = MSBuildToolVersion.VS2017,
    Configuration = "Release",
    PlatformTarget = PlatformTarget.MSIL
};

MSBuild("./src/Cake.sln", settings.WithTarget("Compile");

It should work how you intend it.

To help with this sort of thing, you can run Cake in diagnostic mode, to see exactly what command is being sent to the command line for execution. You can find more about that in this related question:

How to enable diagnostic verbosity for Cake

Gary Ewan Park
  • 17,610
  • 5
  • 42
  • 60
  • Firstly, Thank you for answering. Unfortunately that builds other Targets too. I only want to build a specific Target and nothing else. – Ibz Jul 12 '18 at 13:51
  • I'm not familar with Cake but if you only want specific targets built why not create a new build configuration and feed the name of that configuration into the `Configuration` variable? – Novastorm Jul 12 '18 at 14:00
  • 1
    Have you inspected the command line arguments that are being used when running Cake in diagnostic mode? How does what Cake emit differ from what you are wanting? – Gary Ewan Park Jul 12 '18 at 14:01