private static void Main(string[] args) { string filename = ""; if (args.Length == 0) { Stream myStream = null; OpenFileDialog openFileDialog1 = new OpenFileDialog { Filter = "dll files (*.dll)|*.dll|All files (*.*)|*.*", FilterIndex = 1, RestoreDirectory = true, Multiselect = false }; if (openFileDialog1.ShowDialog() == DialogResult.OK) filename = openFileDialog1.FileName; else return; } else filename = Path.GetFullPath(args[0]); if (File.Exists(filename)) { Package package = new Package(); Assembly executingAssembly = Assembly.GetExecutingAssembly(); using (Stream stream = executingAssembly .GetManifestResourceStream(executingAssembly.GetName().Name + ".Package.nuspec")) { using (StreamReader reader = new StreamReader(stream)) { var xml = reader.ReadToEnd(); package = Package.Deserialize(xml); } } Assembly assembly = Assembly.LoadFile(filename); AssemblyInfoHelper helper = new AssemblyInfoHelper(assembly); IDictionary<string, string> allAttributes = helper.GetAllAttributes(); allAttributes.Add("version", helper.FileVersion); allAttributes.Add("id", helper.AssemblyName); allAttributes.Add("authors", helper.Company); allAttributes.Add("owners", helper.Company); PropertyInfo[] properties = typeof(PackageMetadata).GetProperties( BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance); foreach (KeyValuePair<string, string> attribute in allAttributes) { foreach (PropertyInfo propertyInfo in properties.Where(propertyInfo => propertyInfo.Name.ToLower().Equals(attribute.Key.ToLower())). Where(propertyInfo => propertyInfo.CanWrite)) propertyInfo.SetValue(package.Metadata, attribute.Value, null); } var version = helper.RuntimeVersion; package.Files.Add(new PackageFile { Src = helper.FilePath, Target = "lib" }); var outFile = Path.GetFileName(filename.Replace(".dll", ".nuspec")); package.SaveToFile(outFile); Console.WriteLine("Done! " + outFile); } else Console.WriteLine("File does not exist!"); }
/// <summary> /// Deserializes workflow markup into an Package object /// </summary> /// <param name="xml">string workflow markup to deserialize</param> /// <param name="obj">Output Package object</param> /// <param name="exception">output Exception value if deserialize failed</param> /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns> public static bool Deserialize(string xml, out Package obj, out System.Exception exception) { exception = null; obj = default(Package); try { obj = Deserialize(xml); return true; } catch (System.Exception ex) { exception = ex; return false; } }
/// <summary> /// Deserializes xml markup from file into an Package object /// </summary> /// <param name="fileName">string xml file to load and deserialize</param> /// <param name="obj">Output Package object</param> /// <param name="exception">output Exception value if deserialize failed</param> /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns> public static bool LoadFromFile(string fileName, out Package obj, out System.Exception exception) { exception = null; obj = default(Package); try { obj = LoadFromFile(fileName); return true; } catch (System.Exception ex) { exception = ex; return false; } }
public static bool LoadFromFile(string fileName, out Package obj) { System.Exception exception = null; return LoadFromFile(fileName, out obj, out exception); }
public static bool Deserialize(string xml, out Package obj) { System.Exception exception = null; return Deserialize(xml, out obj, out exception); }