Esempio n. 1
0
        public static ProjectReferenceInfo Parse(String text)
        {
            //Parse from "Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"
            var p  = new ProjectReferenceInfo();
            var ss = text.Split(',');

            p.ID = ss[0];
            foreach (var s in ss)
            {
                var kv = s.Split('=');
                if (kv.Length == 2)
                {
                    switch (kv[0].Trim().ToLower())
                    {
                    case "version": p.Version = kv[1].Trim(); break;

                    case "culture": p.Culture = kv[1].Trim(); break;

                    case "publickeytoken": p.PublicKeyToken = kv[1].Trim(); break;

                    case "processorarchitecture": p.ProcessorArchitecture = kv[1].Trim(); break;

                    default: break;
                    }
                }
            }
            return(p);
        }
Esempio n. 2
0
        public static NugetPackageInfo Create(String projectFilePath)
        {
            var n           = new NugetPackageInfo();
            var folderPath  = Path.GetDirectoryName(projectFilePath);
            var di          = new DirectoryInfo(folderPath);
            var projectName = di.Name;

            n.Nuspec.Id         = Path.GetFileNameWithoutExtension(projectFilePath);
            n.Nuspec.Authors    = "Higty";
            n.Nuspec.Owners     = "Higty";
            n.Nuspec.ProjectUrl = "https://github.com/higty/higlabo";
            n.Nuspec.Tags       = n.Nuspec.Id;

            var AssemblyInfo_cs = File.ReadAllText(Path.Combine(folderPath, "Properties", "AssemblyInfo.cs"));

            {
                var sr = new StringReader(AssemblyInfo_cs);
                while (sr.Peek() > -1)
                {
                    var line = sr.ReadLine();
                    if (line.StartsWith("[assembly: AssemblyVersion("))
                    {
                        n.Nuspec.Version = line.ExtractString('"', '"');
                    }
                    if (line.StartsWith("[assembly: AssemblyDescription("))
                    {
                        n.Nuspec.Description = line.ExtractString('"', '"');
                    }
                    if (line.StartsWith("[assembly: AssemblyCopyright("))
                    {
                        n.Nuspec.Copyright = line.ExtractString('"', '"');
                    }
                }
            }
            if (n.Nuspec.Version.IsNullOrEmpty())
            {
                return(null);
            }
            if (n.Nuspec.Description.IsNullOrEmpty())
            {
                n.Nuspec.Description = "HigLabo library provide features of Mail, Ftp, Rss, ObjectMapper, Converter, ORM, ASP.NET Mvc...etc.See on GitHub(https://github.com/higty/higlabo)";
            }

            var doc = new HtmlDocument();

            doc.LoadHtml(File.ReadAllText(projectFilePath));

            var outputTypeNode = doc.DocumentNode.SelectSingleNode("//propertygroup//outputtype");
            var outputType     = outputTypeNode.InnerText;

            if (outputType != "Library")
            {
                return(null);
            }

            var outputPathNode = doc.DocumentNode.SelectSingleNode("//propertygroup[contains(@condition, 'Release')]//outputpath");
            var dllFolderPath  = String.Format("{0}\\{1}", di.FullName, outputPathNode.InnerText);

            if (Directory.Exists(dllFolderPath) == false)
            {
                return(null);
            }

            var targetFrameworkVersionNode = doc.DocumentNode.SelectSingleNode("//propertygroup//targetframeworkversion");

            n.TargetFrameworkVersion = targetFrameworkVersionNode.InnerText;
            if (n.TargetFrameworkVersion.Contains("Pcl"))
            {
                return(null);
            }

            var dependencyNodes = doc.DocumentNode.SelectNodes("//itemgroup//projectreference");

            if (dependencyNodes != null)
            {
                foreach (var node in dependencyNodes)
                {
                    var path = node.Attributes["Include"].Value;
                    var u    = new Uri(new Uri(projectFilePath), path);
                    LoadDependencyPackages(n.DependencyPackages, u.LocalPath);
                }
                var dd = new List <PackageDependency>();
                foreach (var item in n.DependencyPackages)
                {
                    VersionSpec sVersion = new VersionSpec();
                    sVersion.MinVersion     = new SemanticVersion(item.Nuspec.Version);
                    sVersion.IsMinInclusive = true;
                    dd.Add(new PackageDependency(item.Nuspec.Id, sVersion));
                }
                n.PackageBuilder.DependencySets.Add(new PackageDependencySet(FrameworkNames[n.TargetFrameworkVersion], dd));
            }

            var referenceNodes = doc.DocumentNode.SelectNodes("//itemgroup//reference");

            if (referenceNodes != null)
            {
                var dd = new List <PackageDependency>();
                foreach (var node in referenceNodes)
                {
                    if (node.Attributes["Include"] == null)
                    {
                        continue;
                    }
                    var include = node.Attributes["Include"].Value;
                    var p       = ProjectReferenceInfo.Parse(include);
                    if (String.IsNullOrEmpty(p.Version))
                    {
                        continue;
                    }

                    VersionSpec sVersion = new VersionSpec();
                    sVersion.MinVersion     = new SemanticVersion(p.Version);
                    sVersion.IsMinInclusive = true;
                    dd.Add(new PackageDependency(p.ID, sVersion));
                }
                n.PackageBuilder.DependencySets.Add(new PackageDependencySet(FrameworkNames[n.TargetFrameworkVersion], dd));
            }
            var ff = new List <ManifestFile>();
            var f  = new ManifestFile();

            f.Source = "*.dll";
            f.Target = "lib\\" + FrameworkVersions[n.TargetFrameworkVersion];
            ff.Add(f);
            n.PackageBuilder.PopulateFiles(dllFolderPath, ff);
            n.PackageBuilder.Populate(n.Nuspec);

            return(n);
        }