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).
I expected that DefaultTarget would be used if I do not specify any other target.
0.33
64
Windows
No, local machine.
Create a target like this:
var obfuscate = Task("Obfuscate")
.Does(() => {
MSBuild("obfuscatorConfigurationFile.babel");
});
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.
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
Most helpful comment
We could call it
NoImplicitTargetand it's a just an op-out for the implicit build target. That wayWithTargetwould still be valid.