public static AssemblyDescription FromAssembly(Assembly assembly) { var description = new AssemblyDescription { AssemblyName = assembly.GetName().Name, Dependencies = new List <AssemblyReference>(), }; var assemblyVersion = assembly.GetCustomAttribute <AssemblyVersionAttribute>(); var assemblyFileVersion = assembly.GetCustomAttribute <AssemblyFileVersionAttribute>(); var assemblyInformationalVersion = assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>(); description.AssemblyVersion = assemblyVersion?.Version ?? assembly.GetName().Version?.ToString(); if (assemblyFileVersion != null) { description.AssemblyFileVersion = TryParse(assemblyFileVersion.Version)?.ToString(); } if (assemblyInformationalVersion != null) { description.AssemblyInformationalVersion = assemblyInformationalVersion.InformationalVersion; } var references = assembly.GetReferencedAssemblies(); foreach (var referencedAssembly in references) { description.Dependencies.Add(new AssemblyReference { FullName = referencedAssembly.FullName }); } return(description); }
/// <summary> /// Adds a .NET assembly to the plugin archive. /// </summary> /// <param name="entryName">The relative name of the resulting file in the archive</param> /// <param name="content"></param> /// <param name="header"></param> private Assembly AddAssembly(string entryName, Stream content, PeHeader header) { if (!header.Is32BitHeader) { throw new PackException("Assemblies must be compiled for x86 or AnyCPU"); } byte[] rawAssembly; var assembly = LoadAssemblyFrom(content, out rawAssembly); var targetFramework = assembly.GetCustomAttribute <TargetFrameworkAttribute>(); var version = ParseVersion(targetFramework); // This attribute has been added with .NET 4.0. Tailviewer should obviously // support adding assemblies which target older .NET frameworks where this attribute // is obviously missing and therefore we will tolerate assemblies without it. if (version != null) { if (version > new Version(4, 5, 2)) { throw new PackException("Assemblies may only target frameworks of up to .NET 4.5.2"); } } var assemblyDescription = AssemblyDescription.FromAssembly(assembly); assemblyDescription.EntryName = entryName; AddFile(entryName, rawAssembly); _index.Assemblies.Add(assemblyDescription); foreach (var dependency in assemblyDescription.Dependencies) { var assemblyName = new AssemblyName(dependency.FullName); if (ShouldAddDependency(assemblyName)) { var fileName = Path.Combine(_currentDirectory, string.Format("{0}.exe", assemblyName.Name)); if (!File.Exists(fileName)) { fileName = Path.Combine(_currentDirectory, string.Format("{0}.dll", assemblyName.Name)); } var dependencyEntryName = Path.GetFileName(fileName); AddAssembly(dependencyEntryName, fileName); } } return(assembly); }