예제 #1
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);
        }
    }
예제 #2
0
    public static void CleanBinaries()
    {
        var projectFiles = BuildConfig.Config.ProjectFiles;

        Context.Log.Verbose(string.Format("Cleaning {0} project build directories.", projectFiles.Count));
        foreach (var p in projectFiles)
        {
            // working by convention here. We delete the "obj" directories.
            // This does not care about platform or build configurations - we delete it all.
            var obj = p.GetDirectory().Combine("obj");
            var bin = p.GetDirectory().Combine("bin");
            if (Context.DirectoryExists(bin))
            {
                Context.Log.Debug(string.Format("  Cleaning {0}.", BuildConfig.AsRelativePath(bin)));
                Context.DeleteDirectory(bin, new DeleteDirectorySettings
                {
                    Recursive = true
                });
            }
            if (Context.DirectoryExists(obj))
            {
                Context.Log.Debug(string.Format("  Cleaning {0}.", BuildConfig.AsRelativePath(obj)));
                Context.DeleteDirectory(obj, new DeleteDirectorySettings
                {
                    Recursive = true
                });
            }
        }
    }
예제 #3
0
 public static void CleanPackages()
 {
     if (BuildConfig.Config.SolutionDir != null)
     {
         var packagesDir = BuildConfig.Config.SolutionDir.Combine("packages");
         Context.Log.Verbose(string.Format("Cleaning packages directory: {0}",
                                           BuildConfig.AsRelativePath(packagesDir)));
         if (Context.DirectoryExists(packagesDir))
         {
             Context.Log.Debug(string.Format("  Cleaning {0}.", BuildConfig.AsRelativePath(packagesDir)));
             Context.DeleteDirectory(packagesDir, new DeleteDirectorySettings
             {
                 Recursive = true
             });
         }
     }
 }
예제 #4
0
    /// <summary>
    ///     Parses a project file.
    /// </summary>
    /// <param name="parsedProjectPath">The project path.</param>
    /// <param name="originalProjectFile"></param>
    /// <param name="configuration"></param>
    /// <param name="platform"></param>
    /// <returns>The parsed project.</returns>
    public ExtProjectParserResult Parse(FilePath parsedProjectPath, FilePath originalProjectFile, string configuration,
                                        string platform)
    {
        if (parsedProjectPath == null)
        {
            throw new ArgumentNullException("parsedProjectPath");
        }

        if (parsedProjectPath.IsRelative)
        {
            parsedProjectPath = parsedProjectPath.MakeAbsolute(_environment);
        }

        // Get the project file.
        var file = _fileSystem.GetFile(parsedProjectPath);

        if (!file.Exists)
        {
            const string format  = "Project file '{0}' does not exist.";
            var          message = string.Format(CultureInfo.InvariantCulture, format, parsedProjectPath.FullPath);
            throw new CakeException(message);
        }

        _context.Log.Debug("Parsing " + BuildConfig.AsRelativePath(parsedProjectPath) +
                           " for $(Configuration)|$(Platform) == " + configuration + "|" + platform);

        XDocument document;

        using (var stream = file.OpenRead())
        {
            document = XDocument.Load(stream);
        }

        if (document.Root == null)
        {
            throw new Exception(
                      "Silly error: The parser should never make the root element of a document into a null value");
        }

        var projectProperties = new Dictionary <string, string>();

        projectProperties.Add("Platform", platform);
        projectProperties.Add("Configuration", configuration);

        // Parsing the build file is sensitive to the declared order of elements.
        // If there are include files, then these files must be honored too.
        ParseProjectProperties(configuration, platform, document, projectProperties);

        var rootPath = originalProjectFile.GetDirectory();

        // We only list compile elements
        var projectFiles =
            (from project in document.Elements(ProjectXElement.Project)
             from itemGroup in project.Elements(ProjectXElement.ItemGroup)
             from element in itemGroup.Elements()
             where element.Name == ProjectXElement.Compile ||
             element.Name == ProjectXElement.Content
             from include in element.Attributes("Include")
             let value = include.Value
                         where !string.IsNullOrEmpty(value)
                         let filePath = rootPath.CombineWithFilePath(value)
                                        select new ProjectFile
        {
            FilePath = filePath,
            RelativePath = value,
            Compile = element.Name == ProjectXElement.Compile
        }).ToArray();

        var references =
            (from project in document.Elements(ProjectXElement.Project)
             from itemGroup in project.Elements(ProjectXElement.ItemGroup)
             from element in itemGroup.Elements()
             where element.Name == ProjectXElement.Reference
             from include in element.Attributes("Include")
             let includeValue = include.Value
                                let hintPathElement = element.Element(ProjectXElement.HintPath)
                                                      let nameElement = element.Element(ProjectXElement.Name)
                                                                        let fusionNameElement = element.Element(ProjectXElement.FusionName)
                                                                                                let specificVersionElement = element.Element(ProjectXElement.SpecificVersion)
                                                                                                                             let aliasesElement = element.Element(ProjectXElement.Aliases)
                                                                                                                                                  let privateElement = element.Element(ProjectXElement.Private)
                                                                                                                                                                       select new ProjectAssemblyReference
        {
            Include = includeValue,
            HintPath = string.IsNullOrEmpty((string)hintPathElement)
                    ? null
                    : rootPath.CombineWithFilePath(hintPathElement.Value),
            Name = (string)nameElement,
            FusionName = (string)fusionNameElement,
            SpecificVersion =
                specificVersionElement == null ? (bool?)null : bool.Parse(specificVersionElement.Value),
            Aliases = (string)aliasesElement,
            Private = privateElement == null ? (bool?)null : bool.Parse(privateElement.Value)
        }).ToArray();

        var projectReferences =
            (from project in document.Elements(ProjectXElement.Project)
             from itemGroup in project.Elements(ProjectXElement.ItemGroup)
             from element in itemGroup.Elements()
             where element.Name == ProjectXElement.ProjectReference
             from include in element.Attributes("Include")
             let value = include.Value
                         where !string.IsNullOrEmpty(value)
                         let filePath = rootPath.CombineWithFilePath(value)
                                        let nameElement = element.Element(ProjectXElement.Name)
                                                          let projectElement = element.Element(ProjectXElement.Project)
                                                                               let packageElement = element.Element(ProjectXElement.Package)
                                                                                                    select new ProjectReference
        {
            FilePath = filePath,
            RelativePath = value,
            Name = (string)nameElement,
            Project = (string)projectElement,
            Package =
                string.IsNullOrEmpty((string)packageElement)
                        ? null
                        : rootPath.CombineWithFilePath(packageElement.Value)
        }).ToArray();

        var outputPath = GetValueOrDefault(projectProperties, "OutputPath");

        if (string.IsNullOrEmpty(outputPath))
        {
            return(null);
        }

        return(new ExtProjectParserResult(
                   GetValueOrDefault(projectProperties, "Configuration"),
                   GetValueOrDefault(projectProperties, "Platform"),
                   // Some projects with default configurations do not explicitly specify the platform-target.
                   GetValueOrDefault(projectProperties, "PlatformTarget", GetValueOrDefault(projectProperties, "Platform")),
                   GetValueOrDefault(projectProperties, "ProjectGuid"),
                   GetValueOrDefault(projectProperties, "OutputType", "Library"),
                   GetValueOrDefault(projectProperties, "OutputPath"),
                   GetValueOrDefault(projectProperties, "RootNameSpace"),
                   GetValueOrDefault(projectProperties, "AssemblyName"),
                   GetValueOrDefault(projectProperties, "TargetFrameworkVersion"),
                   GetValueOrDefault(projectProperties, "TargetFrameworkProfile"),
                   projectFiles,
                   references,
                   projectReferences));
    }
예제 #5
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);
            }
        }
    }