Exemplo n.º 1
0
    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);
    }
Exemplo n.º 2
0
    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);
        }
    }
Exemplo n.º 3
0
    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);
        }
    }
Exemplo n.º 4
0
    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));
    }
Exemplo n.º 5
0
    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;
        }
    }
Exemplo n.º 6
0
    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);
    }
Exemplo n.º 7
0
    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);
    }
Exemplo n.º 8
0
    /// <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);
            }
        }
    }