public AssemblyInfoCreatorData(AssemblyInfoSettings settings) { _dictionary = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); _namespaces = new HashSet <string>(StringComparer.OrdinalIgnoreCase); _internalVisibleTo = new HashSet <string>(StringComparer.OrdinalIgnoreCase); // Add attributes. AddAttribute("AssemblyTitle", "System.Reflection", settings.Title); AddAttribute("AssemblyDescription", "System.Reflection", settings.Description); AddAttribute("AssemblyCompany", "System.Reflection", settings.Company); AddAttribute("AssemblyProduct", "System.Reflection", settings.Product); AddAttribute("AssemblyVersion", "System.Reflection", settings.Version); AddAttribute("AssemblyFileVersion", "System.Reflection", settings.FileVersion); AddAttribute("AssemblyInformationalVersion", "System.Reflection", settings.InformationalVersion); AddAttribute("AssemblyCopyright", "System.Reflection", settings.Copyright); AddAttribute("AssemblyTrademark", "System.Reflection", settings.Trademark); AddAttribute("AssemblyConfiguration", "System.Reflection", settings.Configuration); AddAttribute("Guid", "System.Runtime.InteropServices", settings.Guid); AddAttribute("ComVisible", "System.Runtime.InteropServices", settings.ComVisible); AddAttribute("CLSCompliant", "System", settings.CLSCompliant); // Add assemblies that internals are visible to. if (settings.InternalsVisibleTo != null) { foreach (var item in settings.InternalsVisibleTo.Where(item => item != null)) { _internalVisibleTo.Add(string.Concat("InternalsVisibleTo(\"", item.UnQuote(), "\")")); } if (_internalVisibleTo.Count > 0) { _namespaces.Add("System.Runtime.CompilerServices"); } } }
public void Create(FilePath outputPath, AssemblyInfoSettings settings) { if (outputPath == null) { throw new ArgumentNullException("outputPath"); } if (settings == null) { throw new ArgumentNullException("settings"); } var data = new AssemblyInfoCreatorData(settings); outputPath = outputPath.MakeAbsolute(_environment); _log.Verbose("Creating assembly info file: {0}", outputPath); using (var stream = _fileSystem.GetFile(outputPath).OpenWrite()) using (var writer = new StreamWriter(stream, System.Text.Encoding.UTF8)) { writer.WriteLine("//------------------------------------------------------------------------------"); writer.WriteLine("// <auto-generated>"); writer.WriteLine("// This code was generated by Cake."); writer.WriteLine("// </auto-generated>"); writer.WriteLine("//------------------------------------------------------------------------------"); if (data.Namespaces.Count > 0) { var namespaces = data.Namespaces.Select(n => string.Concat("using ", n, ";")); foreach (var @namespace in namespaces) { writer.WriteLine(@namespace); } writer.WriteLine(); } if (data.Attributes.Count > 0) { foreach (var attribute in data.Attributes) { writer.WriteLine(string.Concat("[assembly: ", attribute.Key, "(", attribute.Value, ")]")); } writer.WriteLine(); } if (data.InternalVisibleTo.Count > 0) { foreach (var temp in data.InternalVisibleTo) { writer.WriteLine(string.Concat("[assembly: ", temp, "]")); } writer.WriteLine(); } } }
/// <summary> /// Adds a meta data attribute to the AssemblyInfo settings. /// </summary> /// <param name="settings">The settings.</param> /// <param name="key">The key of the meta data attribute.</param> /// <param name="value">The value for the attribute.</param> /// <returns>The same <see cref="AssemblyInfoSettings"/> instance so that multiple calls can be chained.</returns> public static AssemblyInfoSettings AddMetadataAttribute(this AssemblyInfoSettings settings, string key, string value) { if (settings.MetaDataAttributes == null) { settings.MetaDataAttributes = new List <AssemblyInfoMetadataAttribute>(); } settings.MetaDataAttributes.Add(new AssemblyInfoMetadataAttribute { Key = key, Value = value }); return(settings); }
/// <summary> /// Adds a custom attribute to the AssemblyInfo settings. /// </summary> /// <param name="settings">The settings.</param> /// <param name="name">The name of the custom attribute.</param> /// <param name="namespace">The namespace for the custom attribute.</param> /// <param name="value">The value for the attribute.</param> /// <returns>The same <see cref="AssemblyInfoSettings"/> instance so that multiple calls can be chained.</returns> public static AssemblyInfoSettings AddCustomAttribute(this AssemblyInfoSettings settings, string name, string @namespace, string value) { if (settings.CustomAttributes == null) { settings.CustomAttributes = new List <AssemblyInfoCustomAttribute>(); } settings.CustomAttributes.Add(new AssemblyInfoCustomAttribute() { Name = name, NameSpace = @namespace, Value = value }); return(settings); }
public AssemblyInfoCreatorData(AssemblyInfoSettings settings, bool isVisualBasicAssemblyInfoFile) { _dictionary = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); _customAttributes = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); _metadatattributes = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); _namespaces = new HashSet <string>(StringComparer.OrdinalIgnoreCase); _internalVisibleTo = new HashSet <string>(StringComparer.OrdinalIgnoreCase); _falseStringValue = isVisualBasicAssemblyInfoFile ? "False" : "false"; _trueStringValue = isVisualBasicAssemblyInfoFile ? "True" : "true"; // Add attributes. AddAttribute("AssemblyTitle", "System.Reflection", settings.Title); AddAttribute("AssemblyDescription", "System.Reflection", settings.Description); AddAttribute("AssemblyCompany", "System.Reflection", settings.Company); AddAttribute("AssemblyProduct", "System.Reflection", settings.Product); AddAttribute("AssemblyVersion", "System.Reflection", settings.Version); AddAttribute("AssemblyFileVersion", "System.Reflection", settings.FileVersion); AddAttribute("AssemblyInformationalVersion", "System.Reflection", settings.InformationalVersion); AddAttribute("AssemblyCopyright", "System.Reflection", settings.Copyright); AddAttribute("AssemblyTrademark", "System.Reflection", settings.Trademark); AddAttribute("AssemblyConfiguration", "System.Reflection", settings.Configuration); AddAttribute("Guid", "System.Runtime.InteropServices", settings.Guid); AddAttribute("ComVisible", "System.Runtime.InteropServices", settings.ComVisible); AddAttribute("CLSCompliant", "System", settings.CLSCompliant); // Add assemblies that internals are visible to. if (settings.InternalsVisibleTo != null) { foreach (var item in settings.InternalsVisibleTo.Where(item => item != null)) { _internalVisibleTo.Add(string.Concat("InternalsVisibleTo(\"", item.UnQuote(), "\")")); } if (_internalVisibleTo.Count > 0) { _namespaces.Add("System.Runtime.CompilerServices"); } } if (settings.CustomAttributes != null) { foreach (var item in settings.CustomAttributes.Where(item => item != null)) { AddCustomAttribute(item.Name, item.NameSpace, item.Value, item.UseRawValue); } } if (settings.MetaDataAttributes != null) { foreach (var item in settings.MetaDataAttributes.Where(item => item != null)) { AddMetadataAttribute(item.NameSpace, item.Key, item.Value); } } }
private static IEnumerable <string> GetInternalsVisibleTo(AssemblyInfoSettings settings) { if (!SettingsIncludeInternalsVisibleTo(settings)) { return(null); } var nonEmptyInternalsVisibleTo = settings.InternalsVisibleTo.Where(x => x != null).ToList(); return(nonEmptyInternalsVisibleTo .Select(x => string.Concat("InternalsVisibleTo(\"", x.UnQuote(), "\")")) .ToList()); }
private static bool SettingsIncludeInternalsVisibleTo(AssemblyInfoSettings settings) { if (settings == null) { return(false); } if (settings.InternalsVisibleTo == null || !settings.InternalsVisibleTo.Any()) { return(false); } return(true); }
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, System.Text.Encoding.UTF8)) { // 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, ")]")); } } } }
private static AssemblyInfoRegistration GetRegistrations(AssemblyInfoSettings settings) { var registration = new AssemblyInfoRegistration(); registration.AddString("AssemblyTitle", "System.Reflection", settings.Title); registration.AddString("AssemblyDescription", "System.Reflection", settings.Description); registration.AddString("AssemblyCompany", "System.Reflection", settings.Company); registration.AddString("AssemblyProduct", "System.Reflection", settings.Product); registration.AddString("AssemblyVersion", "System.Reflection", settings.Version); registration.AddString("AssemblyFileVersion", "System.Reflection", settings.FileVersion); registration.AddString("AssemblyInformationalVersion", "System.Reflection", settings.InformationalVersion); registration.AddString("AssemblyCopyright", "System.Reflection", settings.Copyright); registration.AddString("AssemblyTrademark", "System.Reflection", settings.Trademark); registration.AddString("Guid", "System.Runtime.InteropServices", settings.Guid); registration.AddBoolean("ComVisible", "System.Runtime.InteropServices", settings.ComVisible); registration.AddBoolean("CLSCompliant", "System", settings.CLSCompliant); return(registration); }
private static void EnsureInternalVisiblesToNamespace(AssemblyInfoSettings settings, AssemblyInfoRegistration registration) { if (!SettingsIncludeInternalsVisibleTo(settings)) { return; } if (registration == null) { return; } if (registration.Namespaces.Contains("System.Runtime.CompilerServices")) { return; } registration.Namespaces.Add("System.Runtime.CompilerServices"); }
public void Create(FilePath outputPath, AssemblyInfoSettings settings, string attributeFormat = CSharpAttributeFormat, string attributeWithValueFormat = CSharpAttributeWithValueFormat, string attributeWithKeyValueFormat = CSharpAttributeWithKeyValueFormat, string vbAttributeFormat = VBAttributeFormat, string vbAttributeWithValueFormat = VBAttributeWithValueFormat, string vbAttributeWithKeyValueFormat = VBAttributeWithKeyValueFormat) { if (outputPath == null) { throw new ArgumentNullException(nameof(outputPath)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } string comment = CSharpComment; string usingFormat = CSharpUsingFormat; var isVisualBasicAssemblyInfoFile = false; if (outputPath.GetExtension() == ".vb") { isVisualBasicAssemblyInfoFile = true; comment = VBComment; usingFormat = VBUsingFormat; attributeFormat = vbAttributeFormat; attributeWithValueFormat = vbAttributeWithValueFormat; attributeWithKeyValueFormat = vbAttributeWithKeyValueFormat; } var data = new AssemblyInfoCreatorData(settings, isVisualBasicAssemblyInfoFile); outputPath = outputPath.MakeAbsolute(_environment); _log.Verbose("Creating assembly info file: {0}", outputPath); using (var stream = _fileSystem.GetFile(outputPath).OpenWrite()) using (var writer = new StreamWriter(stream, System.Text.Encoding.UTF8)) { writer.WriteLine(comment + "------------------------------------------------------------------------------"); writer.WriteLine(comment + " <auto-generated>"); writer.WriteLine(comment + " This code was generated by Cake."); writer.WriteLine(comment + " </auto-generated>"); writer.WriteLine(comment + "------------------------------------------------------------------------------"); if (data.Namespaces.Count > 0) { var namespaces = data.Namespaces.Select(n => string.Format(usingFormat, n)); foreach (var @namespace in namespaces) { writer.WriteLine(@namespace); } writer.WriteLine(); } if (data.Attributes.Count > 0) { foreach (var attribute in data.Attributes) { writer.WriteLine(string.Format(attributeWithValueFormat, attribute.Key, attribute.Value)); } writer.WriteLine(); } if (data.InternalVisibleTo.Count > 0) { foreach (var temp in data.InternalVisibleTo) { writer.WriteLine(string.Format(attributeFormat, temp)); } writer.WriteLine(); } if (data.CustomAttributes.Count > 0) { writer.WriteLine(comment + " Custom Attributes"); foreach (var attribute in data.CustomAttributes) { writer.WriteLine(string.Format(attributeWithValueFormat, attribute.Key, attribute.Value)); } } if (data.MetadataAttributes.Count > 0) { writer.WriteLine(comment + " Metadata Attributes"); var mdAttribute = new AssemblyInfoMetadataAttribute(); foreach (var attribute in data.MetadataAttributes) { writer.WriteLine(string.Format(attributeWithKeyValueFormat, mdAttribute.Name, attribute.Key, attribute.Value)); } } } }
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); }