-
Notifications
You must be signed in to change notification settings - Fork 29
Added support for logger parameters to MSBuild. #47
base: develop
Are you sure you want to change the base?
Added support for logger parameters to MSBuild. #47
Conversation
Added ConsoleLogger and FileLogger to MSBuildSettings, allowing fluent API specification of parameters for file loggers and the console logger when running MSBuild. Fixes nuke-build/nuke#314
I have no idea what the check failure on macOS is about unfortunately. Is there something I did wrong? |
if (ConsoleLogger == null) | ||
return null; | ||
|
||
var builder = new MSBuildParameterBuilder("/consoleLoggerParameters", emptyParametersAllowed: false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is exactly the part I want the code generation to take over
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree that that would be nice. Question is if this case is common enough to warrant the effort to write code generation for it? If it is, then do you have any ideas for how the specifications would best be extended to support this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't have any initial input, I'll sit down and try to sketch up a suggestion about how the json schema could look to support this, and get back to you to see what you think.
@@ -30,5 +30,23 @@ public static MSBuildSettings AddTeamCityLogger(this MSBuildSettings toolSetting | |||
.AddLoggers($"JetBrains.BuildServer.MSBuildLoggers.MSBuildLogger,{teamCityLogger}") | |||
.EnableNoConsoleLogger(); | |||
} | |||
|
|||
public static MSBuildSettings AddFileLogger(this MSBuildSettings toolSettings, params Func<MSBuildFileLoggerParameters, MSBuildFileLoggerParameters>[] configurators) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this should be done by code generation
Error on macOS is unrelated. |
FYI, it will take a while until I can get into this. In the next release, I plan to do some work around CI system integration. Only after that iteration, I will get to merge this (unless it would look all perfect and shiny). |
No worries. I'll try to come up with a suggestion on how this could be handled by code generation in the meantime, and post a suggestion once I come up with something I feel good about. |
I have now spent some time thinking about how code generation in Nuke could be extended to support this scenario, and I've come up with the following five enhancements that I think would make sense and could be useful also outside of this limited case. I would be more than happy to implement some or all of these and submit a new PR if you like. But first of course I would like your input on these ideas @matkoch, when you've got the time to review them: 1. Conditional FormattingThis is a feature that allows the selection of the The idea is to extend the The various format alternatives would be specified in an array like the following: [
{
"case": true,
"then": "/ShowSummary"
},
{
"case": false,
"then": "/NoSummary"
},
{
"case": null,
"then": "/UseNull"
},
{
"default": "/DoNothing"
}
] The value after a Alternative 1 - Array formatThe format accepts also an array of cases, and a new property The advantage of this variant is that the format specifier is kept fairly compact, while allowing to decide which value to switch on. (The default would be Example: {
"name": "ShowSummary",
"type": "bool",
"switchOn": "{value}",
"format": [
{
"case": true,
"then": "/ShowSummary"
},
{
"case": false,
"then": "/NoSummary"
},
{
"default": "/Dummy"
}
]
} Alternative 2 - Object formatIn this alternative the format specifier is an object instead of an array, encapsulating all information about the format specifier inside that object. The The advantage of this variant is that the format is more encapsulated than in alternative 1 above, in that we no longer have the A possible disadvantage is that it's a bit more verbose to write. {
"name": "ShowSummary",
"type": "bool",
"format": {
"switch": {
"on": "{value}",
"cases": [
{
"case": true,
"then": "/ShowSummary"
},
{
"case": false,
"then": "/NoSummary"
},
{
"default": "/Dummy"
}
]
}
}
} Personally I am in favor of the 2:nd alternative, object format here. 2. Index of array item in format specifierIntroduce the Alternative 1 - indexBase propertyAdd the property Example: {
"name": "FileLoggers",
"type": "List<string>",
"indexBase": 1,
"format": "/flp{index}:{value}"
} Alternative 2 - Include base in specifierThe specifier could include the base, which may be a bit more concise. For example This is the option I would personally prefer. 3. MaxItems specifier on array PropertiesIn the case of MSBuild, at most 9 file loggers are supported. I'd like to introduce a Example: {
"name": "FileLoggers",
"type": "List<string>",
"maxItems": 9,
"format": "/flp{index}:{value}"
} 4. ToString() generation in DataClassesTo allow for a dataclass to produce a single value for a property, as is the case of the file logger parameters in MSBuild, we could add the option to generate a ToString() method on a data class that takes the Suggest adding the
Example (containing a bunch of the previous suggestions as well). "dataClasses": [
{
"name": "MSBuildFileLogger",
"toStringMethod": {
"separator": ";"
},
"properties": [
{
"name": "Summary",
"type": "bool",
"format": [
{
"when": false,
"then": "NoSummary"
},
{
"when": true,
"then": "ShowSummary"
}
]
},
{
"name": "PerformanceSummary",
"type": "bool",
"format": "PerformanceSummary"
},
{
"name": "LogFile",
"type": "string",
"format": "LogFile={value}"
}
]
}
] 5. Additional extension method generationAdd support for generating fluent type configuration methods on single properties as well (Methods accepting a public static MSBuildSettings AddFileLogger(this MSBuildSettings toolSettings, params Func<MSBuildFileLogger, MSBuildFileLogger>[] configurators)
{
var instance = new MSBuildFileLogger();
return toolSettings.AddFileLogger(configurators.Select(configurator => configurator(instance)));
}
public static MSBuildSettings SetFileLogger(this MSBuildXSettings toolSettings, params Func<MSBuildFileLogger, MSBuildFileLogger>[] configurators)
{
var instance = new MSBuildFileLogger();
return toolSettings.SetFileLogger(configurators.Select(configurator => configurator(instance)));
} Suggest adding support for the Example: {
"name": "FileLoggers",
"type": "List<MSBuildFileLogger>",
"extensionMethods": true,
"format": ...
} |
c607572
to
7567604
Compare
ee6640a
to
36aed84
Compare
Would also be possible to add in support for binary logging as well? Or I can do that as a different PR if that makes more sense. |
@david-driscoll That should be doable as well. We just need to come to an agreement on how to implement the support for this with the code generation first I think. Probably no point in implementing it before that. |
0f6a6d9
to
4adeb02
Compare
82e173d
to
3a3910f
Compare
5f5fb10
to
6d93e61
Compare
Added ConsoleLogger and FileLogger to MSBuildSettings, allowing fluent API specification of parameters for file loggers and the console logger when running MSBuild.
Example:
Fixes nuke-build/nuke#314