static XUnitSettings BuildXUnitSettings(ParsedProject projectUnderTest, AnyUnitTestSettings settings, DirectoryPath outputDir) { var outputFile = outputDir.CombineWithFilePath(projectUnderTest.Project.AssemblyName + ".xunit.xml"); var traitArgs = new List <KeyValuePair <string, string> >(); AddTraits(traitArgs, "/-trait", settings.ExcludedTraits); AddTraits(traitArgs, "/trait", settings.IncludedTraits); var s = new XUnitSettings(); XBuildHelper.ApplyToolSettings(s, NUnitToolArgs); s.ShadowCopy = settings.ShadowCopyAssemblies; s.ArgumentCustomization = args => { foreach (var traitArg in traitArgs) { args.Append(traitArg.Key); args.AppendQuoted(traitArg.Value); } args.Append("/xml"); args.AppendQuoted(outputFile.MakeAbsolute(Context.Environment).FullPath); return(args); }; return(s); }
public static void PublishNuGetPackages() { var filePaths = Context.Globber.GetFiles(BuildConfig.TargetDirectory + "/**/*.nupkg").ToList(); foreach (var p in filePaths) { var pushSettings = new NuGetPushSettings(); XBuildHelper.ApplyToolSettings(pushSettings, PushSettings); pushSettings.ArgumentCustomization = PushSettings.ArgumentCustomization; pushSettings.Timeout = PushSettings.Timeout; pushSettings.ConfigFile = PushSettings.ConfigFile; pushSettings.Verbosity = PushSettings.Verbosity; var pathAsString = p.ToString(); if (pathAsString.EndsWith(".symbols.nupkg")) { if (PushSettings.NoSymbols) { continue; } // symbol package pushSettings.ApiKey = PushSettings.SymbolsApiKey; pushSettings.Source = PushSettings.SymbolsSource; if (string.IsNullOrEmpty(pushSettings.Source)) { Context.Log.Information("Skipping package " + BuildConfig.AsRelativePath(p) + " as no valid NuGet symbol server is defined."); continue; } } else { pushSettings.ApiKey = PushSettings.ApiKey; pushSettings.Source = PushSettings.Source; if (string.IsNullOrEmpty(pushSettings.Source)) { Context.Log.Information("Skipping package " + BuildConfig.AsRelativePath(p) + " as no valid NuGet target server is defined."); continue; } } var argsOrg = pushSettings.ArgumentCustomization; pushSettings.ArgumentCustomization = args => { if (argsOrg != null) { args = argsOrg.Invoke(args); } args.Append("-NoSymbols"); args.Append("-NonInteractive"); return(args); }; Context.NuGetPush(p, pushSettings); } }
public static void BuildPackages() { foreach (var p in AdditionalPackages) { NuGetXPackSettings settings; if (p.Value == null) { settings = new NuGetXPackSettings(PackSettings); } else { settings = new NuGetXPackSettings(p.Value); } if (!string.IsNullOrEmpty(Version)) { settings.Properties["version"] = Version; } var targetPath = Context.Directory(string.Format("{0}/{1}/{2}", BuildConfig.TargetDirectory, "user-packages", BuildConfig.Config.Configuration)); var nugetSettings = new NuGetPackSettings(); XBuildHelper.ApplyToolSettings(nugetSettings, settings); nugetSettings.Symbols = settings.Symbols.GetValueOrDefault(); nugetSettings.Properties = new Dictionary <string, string>(settings.Properties); nugetSettings.ArgumentCustomization = settings.ArgumentCustomization; Context.CreateDirectory(targetPath); nugetSettings.WorkingDirectory = targetPath; nugetSettings.Properties["Configuration"] = BuildConfig.Configuration; if (!string.IsNullOrEmpty(Version)) { nugetSettings.Properties["version"] = Version; } if (settings.Tool.GetValueOrDefault()) { var argCustomization = nugetSettings.ArgumentCustomization; nugetSettings.ArgumentCustomization = args => { if (argCustomization != null) { args = argCustomization.Invoke(args); } args.Append("-Tool"); return(args); }; } Context.NuGetPack(p.Key, nugetSettings); } }
public void DotNetMSBuild(FilePath solution, MSBuildSettings settings) { if (settings == null) { settings = new MSBuildSettings(); } var toolSettings = new DotNetCoreBuildSettings(); XBuildHelper.ApplyToolSettings(toolSettings, settings); toolSettings.ArgumentCustomization = settings.ArgumentCustomization; Run(toolSettings, GetMSBuildArguments(solution, settings, environment)); }
public NuGetXPackSettings(NuGetXPackSettings copy) : this() { if (copy == null) { return; } XBuildHelper.ApplyToolSettings(this, copy); ArgumentCustomization = copy.ArgumentCustomization; Tool = copy.Tool; Symbols = copy.Symbols; IncludeReferencedProjects = copy.IncludeReferencedProjects; Verbosity = copy.Verbosity; foreach (var property in copy.Properties) { Properties[property.Key] = property.Value; } }
static MSBuildSettings CreatePreProcessingMSBuildSettings(PlatformTarget target, FilePath targetFile) { var settings = new AnyBuildSettings(BuildConfig.BuildSettings); settings.PlatformTarget = target; var buildSettings = XBuildHelper.CreateMSBuildSettings(settings); var argsCustomizer = buildSettings.ArgumentCustomization; buildSettings.ArgumentCustomization = args => { if (argsCustomizer != null) { args = argsCustomizer.Invoke(args); } args.AppendQuoted("/preprocess:" + targetFile.FullPath); return(args); }; return(buildSettings); }
static NUnitSettings BuildNUnitSettings(ParsedProject projectUnderTest, AnyUnitTestSettings settings, DirectoryPath outputDir) { var s = new NUnitSettings(); XBuildHelper.ApplyToolSettings(s, NUnitToolArgs); if (settings.ExcludedCategories.Count > 0) { s.Exclude = string.Join(",", settings.ExcludedCategories); } if (settings.IncludedCategories.Count > 0) { s.Include = string.Join(",", settings.IncludedCategories); } s.ShadowCopy = settings.ShadowCopyAssemblies; s.UseSingleThreadedApartment = settings.UseSingleThreadedApartment; s.X86 = settings.ForceX86 || projectUnderTest.Platform == PlatformTarget.x86; s.ResultsFile = outputDir.CombineWithFilePath(projectUnderTest.Project.AssemblyName + ".nunit2.xml"); return(s); }
public static void InvokeXBuild(FilePath path, AnyBuildSettings settings, PlatformTarget platformTarget) { settings = new AnyBuildSettings(settings); settings.PlatformTarget = platformTarget; if (settings == null) { throw new ArgumentNullException("settings"); } var targets = new List <string>(); targets.AddRange(settings.Targets); if (targets.Count == 0) { targets.Add("Build"); } var relativeProjectFile = Context.Environment.WorkingDirectory.GetRelativePath(path); Context.Log.Verbose(string.Format("Starting build for {0} with platform {1}", relativeProjectFile, platformTarget)); foreach (var target in targets) { if (Context.Environment.Platform.Family == PlatformFamily.Windows && !BuildConfig.UseXBuildOnWindows) { Context.MSBuild(path, XBuildHelper.CreateMSBuildSettings(settings, target)); } else { Context.XBuild(path, XBuildHelper.CreateXBuildSettings(settings, path, target)); } } Context.Log.Verbose(string.Format("Finished build for {0} with platform {1}", relativeProjectFile, platformTarget)); }
static NUnit3Settings BuildNUnit3Settings(ParsedProject projectUnderTest, AnyUnitTestSettings settings, DirectoryPath outputDir) { var whereClause = BuildNUnit3WhereClause(settings); var s = new NUnit3Settings(); XBuildHelper.ApplyToolSettings(s, NUnitToolArgs); s.ShadowCopy = settings.ShadowCopyAssemblies; s.X86 = settings.ForceX86 || projectUnderTest.Platform == PlatformTarget.x86; var path = outputDir.CombineWithFilePath(projectUnderTest.Project.AssemblyName + ".nunit3.xml"); NUnit3Result rxx = new NUnit3Result(); rxx.FileName = path; rxx.Format = "nunit3"; rxx.Transform = null; s.Results = new List <NUnit3Result> { rxx }; s.ArgumentCustomization = args => { if (whereClause != null) { args.Append("--where"); args.AppendQuoted(whereClause); } // Additionally generate NUnit2 output. AppendNUnit3AlternativeOutput(args, outputDir.CombineWithFilePath(projectUnderTest.Project.AssemblyName + ".nunit2.xml")); return(args); }; return(s); }
/// <summary> /// Thanks to NuGet being an extension of VisualStudio instead of a proper standalone /// tool (just look at the tight binding of 'nuget pack .xxproj' into MSBuild internals /// and the massive amount of code just to manage that stuff), we cannot build NuGet /// packages from existing binaries by just looking at the project and nuspec files. /// Therefore we preemtively produce nuget packages as soon as the compiler finished /// building the project (and before any testing has been done). We then copy the /// NuGet package into a safe place before eventually pushing it to a server or achiving /// the files by other means. /// </summary> /// <param name="project"></param> public static void ProduceNuGetPackage(ParsedProject project) { var nuspec = project.ProjectFile.ChangeExtension(".nuspec"); if (!Context.FileExists(nuspec)) { Context.Log.Verbose("Skipping package as there is no *.nuspec file for project " + BuildConfig.AsRelativePath(project.ProjectFile)); return; } var settings = new NuGetXPackSettings(PackSettings); if (PackSettingsCustomisation != null) { settings = PackSettingsCustomisation.Invoke(settings, project); } var nugetSettings = new NuGetPackSettings(); XBuildHelper.ApplyToolSettings(nugetSettings, settings); nugetSettings.Verbosity = settings.Verbosity; nugetSettings.Symbols = settings.Symbols.GetValueOrDefault(); nugetSettings.IncludeReferencedProjects = settings.IncludeReferencedProjects.GetValueOrDefault(); nugetSettings.Properties = new Dictionary <string, string>(settings.Properties); nugetSettings.ArgumentCustomization = settings.ArgumentCustomization; if (NuGetPackSettingsCustomisation != null) { nugetSettings = NuGetPackSettingsCustomisation.Invoke(nugetSettings, project); if (nugetSettings.Properties == null) { nugetSettings.Properties = new Dictionary <string, string>(); } } var targetPath = BuildConfig.ComputeOutputPath("packages", project); Context.CreateDirectory(targetPath); nugetSettings.WorkingDirectory = targetPath; nugetSettings.Properties["Configuration"] = BuildConfig.Configuration; nugetSettings.Properties["Platform"] = BuildConfig.ConvertPlatformTargetToString(project.Platform); if (!string.IsNullOrEmpty(Version)) { Context.Log.Information("Publishing package as version " + Version); nugetSettings.Properties["version"] = Version; nugetSettings.Version = Version; } if (settings.Tool.GetValueOrDefault()) { var argCustomization = nugetSettings.ArgumentCustomization; nugetSettings.ArgumentCustomization = args => { if (argCustomization != null) { args = argCustomization.Invoke(args); } args.Append("-Tool"); return(args); }; } Context.NuGetPack(project.ProjectFile, nugetSettings); var assembly = LoadZipAssembly(); if (assembly != null) { Context.Log.Information("Unzipping nuget package: " + targetPath.FullPath + "/*.nupkg"); foreach (var file in Context.Globber.GetFiles(targetPath.FullPath + "/*.nupkg")) { Context.Log.Information("Unzipping " + file); Unzip(file, targetPath, assembly); } } }
static ProcessArgumentBuilder GetMSBuildArguments(FilePath solution, MSBuildSettings settings, ICakeEnvironment env) { var builder = new ProcessArgumentBuilder(); builder.Append("msbuild"); // Set the maximum number of processors? if (settings.MaxCpuCount != null) { builder.Append(settings.MaxCpuCount > 0 ? string.Concat("/m:", settings.MaxCpuCount) : "/m"); } // Set the detailed summary flag. if (settings.DetailedSummary.GetValueOrDefault()) { builder.Append("/ds"); } // Set the no console logger flag. if (settings.NoConsoleLogger.GetValueOrDefault()) { builder.Append("/noconlog"); } // Set the verbosity. builder.Append(string.Format(CultureInfo.InvariantCulture, "/v:{0}", GetVerbosityName(settings.Verbosity))); if (settings.NodeReuse != null) { builder.Append(string.Concat("/nr:", settings.NodeReuse.Value ? "true" : "false")); } // Got a specific configuration in mind? if (!string.IsNullOrWhiteSpace(settings.Configuration)) { builder.AppendSwitchQuoted("/p:Configuration", "=", settings.Configuration); } // Build for a specific platform? if (settings.PlatformTarget.HasValue) { var platform = settings.PlatformTarget.Value; var isSolution = string.Equals(solution.GetExtension(), ".sln", StringComparison.OrdinalIgnoreCase); builder.Append(string.Concat("/p:Platform=", XBuildHelper.GetPlatformName(platform, isSolution))); } // Got any properties? if (settings.Properties.Count > 0) { foreach (var property in settings.Properties) { var propertyKey = property.Key; foreach (var propertyValue in property.Value) { var arg = string.Concat("/p:", propertyKey, "=", propertyValue); builder.Append(arg); } } } // Got any targets? if (settings.Targets.Count > 0) { var targets = string.Join(";", settings.Targets); builder.Append(string.Concat("/target:", targets)); } if (settings.Loggers.Count > 0) { foreach (var logger in settings.Loggers) { var argument = GetLoggerArgument(logger); builder.Append(argument); } } // Got any file loggers? if (settings.FileLoggers.Count > 0) { var arguments = settings.FileLoggers.Select((logger, index) => { return(GetLoggerArgument(index, logger, env)); }); foreach (var argument in arguments) { builder.Append(argument); } } builder.AppendQuoted(solution.FullPath); return(builder); }
static EffectiveBuildConfig BuildEffectiveConfiguration() { var c = new EffectiveBuildConfig(); if (NoProjectsToBuildHere) { Context.Log.Information("Skipping project parsing. No projects will be built."); c.Configuration = Configuration ?? "Debug"; c.PlatformBuildOrder = new List <PlatformTarget>(); c.ProjectFiles = new List <FilePath>(); c.ProjectsByPlatform = new Dictionary <PlatformTarget, List <ParsedProject> >(); c.SolutionDir = SolutionDir; return(c); } List <FilePath> effectiveProjects; if (Projects != null && Projects.Count > 0) { Context.Log.Information("Using manually defined projects and solution directory for build."); effectiveProjects = new List <FilePath>(); effectiveProjects.AddRange(Projects); if (SolutionDir == null || !Context.DirectoryExists(SolutionDir)) { Context.Warning( "When specifying projects explicitly, provide the solution directory as well to allow auto-cleaning of resolved packages."); } c.SolutionDir = SolutionDir; } else if (Solution != null && Context.FileExists(Solution)) { if (SolutionDir != null) { throw new Exception("When specifying a solution reference, do not specify a solution directory."); } Context.Log.Information("Using manually defined solution for build: " + Context.Environment.WorkingDirectory.GetRelativePath(solution)); effectiveProjects = ParseSolution(Solution); c.SolutionDir = Solution.GetDirectory(); c.Solution = Solution; } else { var filePaths = Context.Globber.GetFiles("**/*.sln").ToList(); switch (filePaths.Count) { case 0: throw new Exception( "Unable to find a solution file in this directory. Try to specify the solution file manually or list the projects."); case 1: Context.Log.Information("Using automatically defined solution for build: " + Context.Environment.WorkingDirectory.GetRelativePath(filePaths[0])); effectiveProjects = ParseSolution(filePaths[0]); c.Solution = filePaths[0]; c.SolutionDir = c.Solution.GetDirectory(); break; default: throw new Exception("Found more than one solution to build. Please specify the solution explicitly."); } } if (effectiveProjects.Count == 0) { throw new Exception("No projects to build."); } c.Configuration = Configuration ?? "Debug"; c.ProjectFiles = effectiveProjects; foreach (var proj in effectiveProjects) { Context.Log.Information(" Found project " + Context.Environment.WorkingDirectory.GetRelativePath(proj)); } // unless defined otherwise, we attempt to build every supported platform. var platforms = Platforms.Count > 0 ? Platforms : new List <PlatformTarget>(new[] { PlatformTarget.MSIL, PlatformTarget.x86, PlatformTarget.x64, PlatformTarget.ARM }); var parseResult = XBuildHelper.ParseProjects(Context, c.Configuration, platforms, c.ProjectFiles); if (c.Solution != null) { parseResult = new ExtendedSolutionParser().Filter(Context, c.Solution, parseResult, c.Configuration); } c.PlatformBuildOrder = parseResult.PlatformBuildOrder; c.ProjectsByPlatform = parseResult.ProjectsByPlatform; Context.Log.Information("Project summary by platform type"); Context.Log.Information("--------------------------------"); if (c.Solution != null) { Context.Log.Information(" Solution: " + Context.Environment.WorkingDirectory.GetRelativePath(c.Solution)); } if (c.SolutionDir != null) { Context.Log.Information(" Solution-Directory: " + Context.Environment.WorkingDirectory.GetRelativePath(c.SolutionDir)); } foreach (var platform in platforms) { Context.Log.Information("Platform " + platform); List <ParsedProject> list; if (!c.ProjectsByPlatform.TryGetValue(platform, out list)) { Context.Log.Information(" <no projects defined>"); } else { foreach (var project in list) { Context.Log.Information(" " + Context.Environment.WorkingDirectory.GetRelativePath(project.ProjectFile) + "; OutputPath=" + Context.Environment.WorkingDirectory.GetRelativePath( project.Project.OutputPath.MakeAbsolute(Context.Environment))); } } } Context.Log.Information("--------------------------------"); return(c); }