private static AssemblyInfoRegistration GetRegistrations(AssemblyInfoSettings settings)
        {
            var registration = new AssemblyInfoRegistration();

            if (settings.Title != null)
            {
                registration.AddString("AssemblyTitle", "System.Reflection", settings.Title);
            }
            if (settings.Description != null)
            {
                registration.AddString("AssemblyDescription", "System.Reflection", settings.Description);
            }
            if (settings.Product != null)
            {
                registration.AddString("AssemblyProduct", "System.Reflection", settings.Product);
            }
            if (settings.Version != null)
            {
                registration.AddString("AssemblyVersion", "System.Reflection", settings.Version);
            }
            if (settings.FileVersion != null)
            {
                registration.AddString("AssemblyFileVersion", "System.Reflection", settings.FileVersion);
            }
            if (settings.InformationalVersion != null)
            {
                registration.AddString("AssemblyInformationalVersion", "System.Reflection", settings.InformationalVersion);
            }
            if (settings.Copyright != null)
            {
                registration.AddString("AssemblyCopyright", "System.Reflection", settings.Copyright);
            }
            if (settings.Trademark != null)
            {
                registration.AddString("AssemblyTrademark", "System.Reflection", settings.Trademark);
            }
            if (settings.Guid != null)
            {
                registration.AddString("Guid", "System.Runtime.InteropServices", settings.Guid);
            }
            if (settings.ComVisible != null)
            {
                registration.AddBoolean("ComVisible", "System.Runtime.InteropServices", settings.ComVisible.Value);
            }
            if (settings.CLSCompliant != null)
            {
                registration.AddBoolean("CLSCompliant", "System.Runtime.InteropServices", settings.CLSCompliant.Value);
            }

            return(registration);
        }
        public void Create(FilePath outputPath, AssemblyInfoSettings settings)
        {
            if (outputPath == null)
            {
                throw new ArgumentNullException("outputPath");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            // Create registrations.
            var registration = GetRegistrations(settings);

            // Get the absolute output path.
            var absoluteOutputPath = outputPath.MakeAbsolute(_environment);

            _log.Verbose("Creating assembly info file: {0}", absoluteOutputPath);

            using (var stream = _fileSystem.GetFile(absoluteOutputPath).OpenWrite())
                using (var writer = new StreamWriter(stream))
                {
                    // Write header.
                    writer.WriteLine("//------------------------------------------------------------------------------");
                    writer.WriteLine("// <auto-generated>");
                    writer.WriteLine("//     This code was generated by Cake.");
                    writer.WriteLine("// </auto-generated>");
                    writer.WriteLine("//------------------------------------------------------------------------------");

                    if (registration.Attributes.Count > 0)
                    {
                        // Write namespaces.
                        var namespaces = registration.Namespaces.Select(n => string.Concat("using ", n, ";"));
                        foreach (var @namespace in namespaces)
                        {
                            writer.WriteLine(@namespace);
                        }

                        writer.WriteLine();

                        // Write attributes.
                        foreach (var attribute in registration.Attributes)
                        {
                            writer.WriteLine(string.Concat("[assembly: ", attribute.Key, "(", attribute.Value, ")]"));
                        }
                    }
                }
        }
Exemple #3
0
        public static void CreateAssemblyInfo(this ICakeContext context, FilePath outputPath, AssemblyInfoSettings settings)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var creator = new AssemblyInfoCreator(context.FileSystem, context.Environment, context.Log);

            creator.Create(outputPath, settings);
        }