Cake: Call MSBuild without specifying a target does not use DefaultTarget

Created on 11 May 2019  路  11Comments  路  Source: cake-build/cake

What You Are Seeing?

When I call MSBuild without specifying WithTarget(), it looks like MSBuild tries to build my project using "Build" target instead of using the file's DefaultTarget.

I'm calling a MSBuild-compatible XML file as the solution input (namely Babel Obfuscator's configuration file, which I can execute through the command line using MSBuild).

What is Expected?

I expected that DefaultTarget would be used if I do not specify any other target.

What version of Cake are you using?

0.33

Are you running on a 32 or 64 bit system?

64

What environment are you running on? Windows? Linux? Mac?

Windows

Are you running on a CI Server? If so, which one?

No, local machine.

How Did You Get This To Happen? (Steps to Reproduce)

Create a target like this:

var obfuscate = Task("Obfuscate")
    .Does(() => {
        MSBuild("obfuscatorConfigurationFile.babel");
    });

Output Log

Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 11/05/2019 21:51:34.
Project "C:\svn\branch\ObfuscationConfiguration.babel" on node 1 (Build target(s)).
"C:\svn\branch\ObfuscationConfiguration.babel" (Build target) (1) ->
C:\svn\branch\ObfuscationConfiguration.babel : error MSB4057: The target "Build" does not exist in the project.

Improvement

Most helpful comment

We could call it NoImplicitTarget and it's a just an op-out for the implicit build target. That way WithTarget would still be valid.

All 11 comments

Well I have been looking at the code and it defaults to target:Build if no Target is passed, as I observed.

Why not calling msbuild without the Target parameter if no Target is provided? Any reason for it to be implemented that way?

We are running into the same problem.

I understand the fact that it might not be possible to change how the default is implemented (since it might potentially break a lot of existing scripts), but there needs to at least be some way of overriding the way that Cake automatically defaults to target:Build if there is no Target passed, so that we can call MSBuild with an empty target.

This is currently blocking us from moving to Cake.

Could have a NoTarget that defaults to false on MSBuild settings class. That way there's a flag to opt-out, with retained backwards compat.

@devlead yup, just thought about doing something in that way. May I make a PR for this?

Sure go ahead.

@z93blom Not possible to do a settings.Targets.Clear(); before passing the settings to MSBuild alias?

@patriksvensson Unfortunately not. The "transform" is done when running the MSBuild alias (see MSBuildRunner.cs, 112-120). It is automatically defaulting to "/target:Build" if there are no targets, instead of relying on there being a "DefaultTargets" specified in the project file.

The way to go forwards is the proposed solution by @devlead. Looking forward to @Diogomrol 's PR.

Usability question: the NoTarget should only "work" if the user doesn't specify any WithTarget() or it should always avoid that targets are passed to run MSBuild?

I'm not sure about which behavior would be more appropriate so I'd love some thoughts on this :)

We could call it NoImplicitTarget and it's a just an op-out for the implicit build target. That way WithTarget would still be valid.

@devlead like that, I will make it that way then :)

Fixed by #2557

Was this page helpful?
0 / 5 - 0 ratings