/// <summary> /// Generates an AssemblyInfo file. /// </summary> protected override void ExecuteTask() { try { StringCollection imports = new StringCollection(); foreach (NamespaceImport import in Imports) { if (import.IfDefined && !import.UnlessDefined) { imports.Add(import.Namespace); } } // ensure base directory is set, even if fileset was not initialized // from XML if (References.BaseDirectory == null) { References.BaseDirectory = new DirectoryInfo(Project.BaseDirectory); } // write out code to memory stream, so we can compare it later // to what is already present (if necessary) MemoryStream generatedAsmInfoStream = new MemoryStream(); using (StreamWriter writer = new StreamWriter(generatedAsmInfoStream, Encoding.Default)) { // create new instance of CodeProviderInfo for specified CodeLanguage CodeProvider codeProvider = new CodeProvider(this, Language); // only generate imports here for C#, for VB we create the // imports as part of the assembly attributes compile unit if (Language == CodeLanguage.CSharp) { // generate imports code codeProvider.GenerateImportCode(imports, writer); } // generate code for assembly attributes codeProvider.GenerateAssemblyAttributesCode(AssemblyAttributes, imports, References.FileNames, writer); // flush writer.Flush(); // check whether generated source should be persisted if (NeedsPersisting(generatedAsmInfoStream)) { using (FileStream fs = new FileStream(Output.FullName, FileMode.Create, FileAccess.Write)) { byte[] buffer = generatedAsmInfoStream.ToArray(); fs.Write(buffer, 0, buffer.Length); fs.Flush(); fs.Close(); generatedAsmInfoStream.Close(); } Log(Level.Info, ResourceUtils.GetString("String_GeneratedFile"), Output.FullName); } else { Log(Level.Verbose, ResourceUtils.GetString("String_FileUpToDate"), Output.FullName); } } } catch (Exception ex) { throw new BuildException(string.Format( CultureInfo.InvariantCulture, ResourceUtils.GetString("NA2004"), Output.FullName), Location, ex); } }