/// <summary> /// Adds a MSBuild target to the configuration. /// </summary> /// <param name="settings">The settings.</param> /// <param name="target">The MSBuild target.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> /// <remarks>Ignores a target if already added.</remarks> public static DotNetCoreMSBuildSettings WithTarget(this DotNetCoreMSBuildSettings settings, string target) { EnsureSettings(settings); if (!settings.Targets.Contains(target)) { settings.Targets.Add(target); } return(settings); }
/// <summary> /// Sets the warning code to treats as a message. /// </summary> /// <param name="settings">The settings.</param> /// <param name="warningCode">The warning code to treat as a message.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings SetWarningCodeAsMessage(this DotNetCoreMSBuildSettings settings, string warningCode) { EnsureSettings(settings); if (string.IsNullOrWhiteSpace(warningCode)) { throw new ArgumentException("Warning code cannot be null or empty", nameof(warningCode)); } settings.WarningCodesAsMessage.Add(warningCode); return(settings); }
/// <summary> /// Adds a file logger. /// </summary> /// <param name="settings">The settings.</param> /// <param name="fileLoggerParameters">Parameters to be passed to the logger.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> /// <remarks> /// Each file logger will be declared in the order added. /// The first file logger will match up to the /fl parameter. /// The next nine (max) file loggers will match up to the /fl1 through /fl9 respectively. /// </remarks> public static DotNetCoreMSBuildSettings AddFileLogger(this DotNetCoreMSBuildSettings settings, MSBuildFileLoggerSettings fileLoggerParameters) { EnsureSettings(settings); if (fileLoggerParameters == null) { throw new ArgumentNullException(nameof(fileLoggerParameters)); } settings.FileLoggers.Add(fileLoggerParameters); return(settings); }
/// <summary> /// Adds a property to the configuration. /// </summary> /// <param name="settings">The settings.</param> /// <param name="name">The property name.</param> /// <param name="values">The property values.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings WithProperty(this DotNetCoreMSBuildSettings settings, string name, params string[] values) { EnsureSettings(settings); ICollection <string> currentValue; // try to get existing values of properties and add new property values currentValue = settings.Properties.TryGetValue(name, out currentValue) && currentValue != null ? currentValue.Concat(values).ToList() : new List <string>(values); settings.Properties[name] = currentValue; return(settings); }
/// <summary> /// Enables the binary logger with the specified imports and default file name. /// </summary> /// <param name="settings">The settings.</param> /// <param name="imports">The imports.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings EnableBinaryLogger(this DotNetCoreMSBuildSettings settings, MSBuildBinaryLoggerImports imports) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } settings.BinaryLogger = new MSBuildBinaryLoggerSettings { Enabled = true, Imports = imports, }; return(settings); }
/// <summary> /// Adds a custom logger. /// </summary> /// <param name="settings">The settings.</param> /// <param name="loggerAssembly">The assembly containing the logger. Should match the format {AssemblyName[,StrongName] | AssemblyFile}</param> /// <param name="loggerClass">The class implementing the logger. Should match the format [PartialOrFullNamespace.]LoggerClassName. If the assembly contains only one logger, class does not need to be specified.</param> /// <param name="loggerParameters">Parameters to be passed to the logger.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings WithLogger(this DotNetCoreMSBuildSettings settings, string loggerAssembly, string loggerClass = null, string loggerParameters = null) { EnsureSettings(settings); if (string.IsNullOrWhiteSpace(loggerAssembly)) { throw new ArgumentException(nameof(loggerAssembly)); } settings.Loggers.Add(new MSBuildLogger { Assembly = loggerAssembly, Class = loggerClass, Parameters = loggerParameters }); return(settings); }
/// <summary> /// Sets the package version. /// </summary> /// <param name="settings">The settings.</param> /// <param name="packageVersion">The package version.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings SetPackageVersion(this DotNetCoreMSBuildSettings settings, string packageVersion) => (DotNetCoreMSBuildSettings)DotNet.MSBuild.DotNetMSBuildSettingsExtensions.SetPackageVersion(settings, packageVersion);
/// <summary> /// Adds MSBuild arguments. /// </summary> /// <param name="builder">Argument builder.</param> /// <param name="settings">MSBuild settings to add.</param> /// <param name="environment">The environment.</param> /// <exception cref="InvalidOperationException">Throws if 10 or more file loggers specified.</exception> public static void AppendMSBuildSettings(this ProcessArgumentBuilder builder, DotNetCoreMSBuildSettings settings, ICakeEnvironment environment) { // Got any targets? if (settings.Targets.Any()) { if (settings.Targets.All(string.IsNullOrWhiteSpace)) { throw new ArgumentException("Specify the name of the target", nameof(settings.Targets)); } builder.AppendMSBuildSwitch("target", string.Join(";", settings.Targets)); } // Got any properties? foreach (var property in settings.Properties) { if (property.Value == null || property.Value.All(string.IsNullOrWhiteSpace)) { throw new ArgumentException("A property must have at least one non-empty value", nameof(settings.Properties)); } foreach (var value in property.Value) { if (string.IsNullOrWhiteSpace(value)) { continue; } builder.AppendMSBuildSwitch("property", $"{property.Key}={value.EscapeMSBuildPropertySpecialCharacters()}"); } } // Set the maximum number of processors? if (settings.MaxCpuCount.HasValue) { builder.AppendMSBuildSwitchWithOptionalValue("maxcpucount", settings.MaxCpuCount.Value, maxCpuCount => maxCpuCount > 0); } // use different version of msbuild? if (settings.ToolVersion.HasValue) { builder.AppendMSBuildSwitch("toolsversion", GetToolVersionValue(settings.ToolVersion.Value)); } // configure console logger? if (!settings.DisableConsoleLogger && settings.ConsoleLoggerSettings != null) { var arguments = GetLoggerSettings(settings.ConsoleLoggerSettings); if (arguments.Any()) { builder.AppendMSBuildSwitch("consoleloggerparameters", arguments); } } // disable console logger? if (settings.DisableConsoleLogger) { builder.AppendMSBuildSwitch("noconsolelogger"); } // Got any file loggers? if (settings.FileLoggers.Any()) { if (settings.FileLoggers.Count >= 10) { throw new InvalidOperationException("Too Many FileLoggers"); } var arguments = settings .FileLoggers .Select((logger, index) => GetLoggerArgument(index, logger, environment)) .Where(arg => !string.IsNullOrEmpty(arg)); foreach (var argument in arguments) { builder.Append(argument); } } // Use binary logging? if (settings.BinaryLogger != null && settings.BinaryLogger.Enabled) { string binaryOptions = null; if (!string.IsNullOrEmpty(settings.BinaryLogger.FileName)) { binaryOptions = settings.BinaryLogger.FileName; } if (settings.BinaryLogger.Imports != MSBuildBinaryLoggerImports.Unspecified) { if (!string.IsNullOrEmpty(binaryOptions)) { binaryOptions += ";"; } binaryOptions = binaryOptions + "ProjectImports=" + settings.BinaryLogger.Imports; } builder.AppendMSBuildSwitchWithOptionalValueIfNotEmpty("binarylogger", binaryOptions); } // Got any distributed loggers? foreach (var distributedLogger in settings.DistributedLoggers) { builder.AppendMSBuildSwitch("distributedlogger", $"{GetLoggerValue(distributedLogger.CentralLogger)}*{GetLoggerValue(distributedLogger.ForwardingLogger)}"); } // use a file logger for each node? if (settings.DistributedFileLogger) { builder.AppendMSBuildSwitch("distributedfilelogger"); } // Got any loggers? foreach (var logger in settings.Loggers) { builder.AppendMSBuildSwitch("logger", GetLoggerValue(logger)); } var showWarningsAsError = settings.TreatAllWarningsAs == MSBuildTreatAllWarningsAs.Error || settings.WarningCodesAsError.Any(); var showWarningsAsMessages = settings.TreatAllWarningsAs == MSBuildTreatAllWarningsAs.Message || settings.WarningCodesAsMessage.Any(); // Treat all or some warnings as errors? if (showWarningsAsError) { builder.AppendMSBuildSwitchWithOptionalValueIfNotEmpty("warnaserror", GetWarningCodes(settings.TreatAllWarningsAs == MSBuildTreatAllWarningsAs.Error, settings.WarningCodesAsError)); } // Treat all or some warnings as messages? if (showWarningsAsMessages) { builder.AppendMSBuildSwitchWithOptionalValueIfNotEmpty("warnasmessage", GetWarningCodes(settings.TreatAllWarningsAs == MSBuildTreatAllWarningsAs.Message, settings.WarningCodesAsMessage)); } // set project file extensions to ignore when searching for project file if (settings.IgnoreProjectExtensions.Any()) { builder.AppendMSBuildSwitch("ignoreprojectextensions", string.Join(",", settings.IgnoreProjectExtensions)); } // detailed summary? if (settings.DetailedSummary) { builder.AppendMSBuildSwitch("detailedsummary"); } // Include response files? foreach (var responseFile in settings.ResponseFiles) { builder.AppendSwitchQuoted("@", string.Empty, responseFile.MakeAbsolute(environment).FullPath); } // exclude auto response files? if (settings.ExcludeAutoResponseFiles) { builder.AppendMSBuildSwitch("noautoresponse"); } // don't output MSBuild logo? if (settings.NoLogo) { builder.AppendMSBuildSwitch("nologo"); } // Set Continuous Integration Build? if (settings.ContinuousIntegrationBuild.HasValue) { var continuousIntegrationBuild = settings.ContinuousIntegrationBuild.Value ? "true" : "false"; builder.AppendMSBuildSwitch("property", $"ContinuousIntegrationBuild={continuousIntegrationBuild}"); } }
/// <summary> /// Enables the binary logger with the specified log file name and no imports. /// </summary> /// <param name="settings">The settings.</param> /// <param name="fileName">The log file name.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings EnableBinaryLogger(this DotNetCoreMSBuildSettings settings, string fileName) { return(EnableBinaryLogger(settings, fileName, MSBuildBinaryLoggerImports.Unspecified)); }
/// <summary> /// Suppress warning CS7035. /// This is useful when using semantic versioning and either the file or informational version /// doesn't match the recommended format. /// The recommended format is: major.minor.build.revision where /// each is an integer between 0 and 65534 (inclusive). /// </summary> /// <param name="settings">The settings.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings SuppressVersionRecommendedFormatWarning(this DotNetCoreMSBuildSettings settings) => (DotNetCoreMSBuildSettings)DotNet.MSBuild.DotNetMSBuildSettingsExtensions.SuppressVersionRecommendedFormatWarning(settings);
/// <summary> /// Sets the version Suffix. /// </summary> /// <param name="settings">The settings.</param> /// <param name="versionSuffix">The version prefix.</param> /// <returns>The same <see cref="MSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings SetVersionSuffix(this DotNetCoreMSBuildSettings settings, string versionSuffix) => settings.WithProperty("VersionSuffix", versionSuffix);
/// <summary> /// Sets the informational version. /// </summary> /// <param name="settings">The settings.</param> /// <param name="informationalVersion">The informational version.</param> /// <returns>The same <see cref="MSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings SetInformationalVersion(this DotNetCoreMSBuildSettings settings, string informationalVersion) => settings.WithProperty("InformationalVersion", informationalVersion);
/// <summary> /// Sets the configuration. /// </summary> /// <param name="settings">The settings.</param> /// <param name="configuration">The configuration.</param> /// <returns>The same <see cref="MSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings SetConfiguration(this DotNetCoreMSBuildSettings settings, string configuration) => settings.WithProperty("configuration", configuration);
/// <summary> /// Exclude any MSBuild.rsp files automatically. /// </summary> /// <param name="settings">The settings.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings ExcludeAutoResponseFiles(this DotNetCoreMSBuildSettings settings) { return((DotNetCoreMSBuildSettings)DotNet.MSBuild.DotNetMSBuildSettingsExtensions.ExcludeAutoResponseFiles(settings)); }
/// <summary> /// Sets the maximum CPU count. Without this set MSBuild will compile projects in this solution one at a time. /// </summary> /// <param name="settings">The settings.</param> /// <param name="maxCpuCount">The maximum CPU count. Set this value to zero to use as many MSBuild processes as available CPUs.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings SetMaxCpuCount(this DotNetCoreMSBuildSettings settings, int?maxCpuCount) { return((DotNetCoreMSBuildSettings)DotNet.MSBuild.DotNetMSBuildSettingsExtensions.SetMaxCpuCount(settings, maxCpuCount)); }
/// <summary> /// Adds a extension to ignore when determining which project file to build. /// </summary> /// <param name="settings">The settings.</param> /// <param name="extension">The extension to ignore.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings WithIgnoredProjectExtension(this DotNetCoreMSBuildSettings settings, string extension) { return((DotNetCoreMSBuildSettings)DotNet.MSBuild.DotNetMSBuildSettingsExtensions.WithIgnoredProjectExtension(settings, extension)); }
/// <summary> /// Shows detailed information at the end of the build log about the configurations that were built and how they were scheduled to nodes. /// </summary> /// <param name="settings">The settings.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings ShowDetailedSummary(this DotNetCoreMSBuildSettings settings) { return((DotNetCoreMSBuildSettings)DotNet.MSBuild.DotNetMSBuildSettingsExtensions.ShowDetailedSummary(settings)); }
/// <summary> /// Sets a target operating systems where the application or assembly will run. /// </summary> /// <param name="settings">The settings.</param> /// <param name="runtimeId">The runtime id of the operating system.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> /// <remarks> /// For list of runtime ids see https://docs.microsoft.com/en-us/dotnet/core/rid-catalog. /// </remarks> public static DotNetCoreMSBuildSettings SetRuntime(this DotNetCoreMSBuildSettings settings, string runtimeId) => (DotNetCoreMSBuildSettings)DotNet.MSBuild.DotNetMSBuildSettingsExtensions.SetRuntime(settings, runtimeId);
/// <summary> /// Adds a framework to target. /// </summary> /// <param name="settings">The settings.</param> /// <param name="targetFramework">The framework to target.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> /// <remarks> /// For list of target frameworks see https://docs.microsoft.com/en-us/dotnet/standard/frameworks. /// </remarks> public static DotNetCoreMSBuildSettings SetTargetFramework(this DotNetCoreMSBuildSettings settings, string targetFramework) => (DotNetCoreMSBuildSettings)DotNet.MSBuild.DotNetMSBuildSettingsExtensions.SetTargetFramework(settings, targetFramework);
/// <summary> /// Sets the version Suffix. /// </summary> /// <param name="settings">The settings.</param> /// <param name="versionSuffix">The version prefix.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings SetVersionSuffix(this DotNetCoreMSBuildSettings settings, string versionSuffix) => (DotNetCoreMSBuildSettings)DotNet.MSBuild.DotNetMSBuildSettingsExtensions.SetVersionSuffix(settings, versionSuffix);
/// <summary> /// Sets the informational version. /// </summary> /// <param name="settings">The settings.</param> /// <param name="informationalVersion">The informational version.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings SetInformationalVersion(this DotNetCoreMSBuildSettings settings, string informationalVersion) => (DotNetCoreMSBuildSettings)DotNet.MSBuild.DotNetMSBuildSettingsExtensions.SetInformationalVersion(settings, informationalVersion);
/// <summary> /// Hide the startup banner and the copyright message. /// </summary> /// <param name="settings">The settings.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings HideLogo(this DotNetCoreMSBuildSettings settings) { return((DotNetCoreMSBuildSettings)DotNet.MSBuild.DotNetMSBuildSettingsExtensions.HideLogo(settings)); }
/// <summary> /// Sets the file version. /// </summary> /// <param name="settings">The settings.</param> /// <param name="fileVersion">The file version.</param> /// <returns>The same <see cref="MSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings SetFileVersion(this DotNetCoreMSBuildSettings settings, string fileVersion) => settings.WithProperty("FileVersion", fileVersion);
/// <summary> /// Adds a framework to target. /// </summary> /// <param name="settings">The settings.</param> /// <param name="targetFramework">The framework to target.</param> /// <returns>The same <see cref="MSBuildSettings"/> instance so that multiple calls can be chained.</returns> /// <remarks> /// For list of target frameworks see https://docs.microsoft.com/en-us/dotnet/standard/frameworks. /// </remarks> public static DotNetCoreMSBuildSettings SetTargetFramework(this DotNetCoreMSBuildSettings settings, string targetFramework) => settings.WithProperty("TargetFrameworks", targetFramework);
/// <summary> /// Suppress warning CS7035. /// This is useful when using semantic versioning and either the file or informational version /// doesn't match the recommended format. /// The recommended format is: major.minor.build.revision where /// each is an integer between 0 and 65534 (inclusive). /// </summary> /// <param name="settings">The settings.</param> /// <returns>The same <see cref="MSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings SuppressVersionRecommendedFormatWarning(this DotNetCoreMSBuildSettings settings) => settings.WithProperty("nowarn", "7035");
/// <summary> /// Sets the assembly version. /// </summary> /// <param name="settings">The settings.</param> /// <param name="assemblyVersion">The assembly version.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings SetAssemblyVersion(this DotNetCoreMSBuildSettings settings, string assemblyVersion) => (DotNetCoreMSBuildSettings)DotNet.MSBuild.DotNetMSBuildSettingsExtensions.SetAssemblyVersion(settings, assemblyVersion);
/// <summary> /// Sets a value indicating whether to normalize stored file paths used when producing deterministic builds. /// </summary> /// <remarks> /// For more information see https://devblogs.microsoft.com/dotnet/producing-packages-with-source-link/#deterministic-builds. /// </remarks> /// <param name="settings">The settings.</param> /// <param name="continuousIntegrationBuild">A value indicating whether to normalize stored file paths used when producing deterministic builds.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings SetContinuousIntegrationBuild(this DotNetCoreMSBuildSettings settings, bool?continuousIntegrationBuild = true) { return((DotNetCoreMSBuildSettings)DotNet.MSBuild.DotNetMSBuildSettingsExtensions.SetContinuousIntegrationBuild(settings, continuousIntegrationBuild)); }
/// <summary> /// Sets the package release notes. /// </summary> /// <param name="settings">The settings.</param> /// <param name="packageReleaseNotes">The package release notes.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> public static DotNetCoreMSBuildSettings SetPackageReleaseNotes(this DotNetCoreMSBuildSettings settings, string packageReleaseNotes) => (DotNetCoreMSBuildSettings)DotNet.MSBuild.DotNetMSBuildSettingsExtensions.SetPackageReleaseNotes(settings, packageReleaseNotes);
/// <summary> /// Sets a target operating systems where the application or assembly will run. /// </summary> /// <param name="settings">The settings.</param> /// <param name="runtimeId">The runtime id of the operating system.</param> /// <returns>The same <see cref="MSBuildSettings"/> instance so that multiple calls can be chained.</returns> /// <remarks> /// For list of runtime ids see https://docs.microsoft.com/en-us/dotnet/core/rid-catalog. /// </remarks> public static DotNetCoreMSBuildSettings SetRuntime(this DotNetCoreMSBuildSettings settings, string runtimeId) => settings.WithProperty("RuntimeIdentifiers", runtimeId);
/// <summary> /// Adds a file logger with all the default settings. /// </summary> /// <param name="settings">The settings.</param> /// <returns>The same <see cref="DotNetCoreMSBuildSettings"/> instance so that multiple calls can be chained.</returns> /// <remarks> /// Each file logger will be declared in the order added. /// The first file logger will match up to the /fl parameter. /// The next nine (max) file loggers will match up to the /fl1 through /fl9 respectively. /// </remarks> public static DotNetCoreMSBuildSettings AddFileLogger(this DotNetCoreMSBuildSettings settings) { return(AddFileLogger(settings, new MSBuildFileLoggerSettings())); }