Ejemplo n.º 1
0
        ManifestDependencySet GetDependencySet(string framework)
        {
            var set = Metadata.DependencySets.Find(d => d.TargetFramework == framework);

            if (set == null)
            {
                set = new ManifestDependencySet()
                {
                    TargetFramework = framework
                };
                set.Dependencies = new List <ManifestDependency>();
                Metadata.DependencySets.Add(set);
            }
            return(set);
        }
        private static List <ManifestDependencySet> CreateManifestDependencySet(IPackage package, string destination)
        {
            List <ManifestDependencySet> depSetList = new List <ManifestDependencySet>();
            ManifestDependencySet        depSet     = new ManifestDependencySet();
            List <ManifestDependency>    depList    = new List <ManifestDependency>();
            var dependencies = from dSets in package.DependencySets
                               from d in dSets.Dependencies
                               select d;

            foreach (var d in dependencies)
            {
                ManifestDependency manDep = new ManifestDependency();
                manDep.Id      = d.Id;
                manDep.Exclude = d.Exclude;
                manDep.Include = d.Include;
                manDep.Version = GetLatestPackageVersion(d.Id, d.VersionSpec.ToString(), destination);
                depList.Add(manDep);
            }
            depSet.Dependencies = depList;
            depSetList.Add(depSet);
            return(depSetList);
        }
Ejemplo n.º 3
0
 private static void AssertDependencySet(ManifestDependencySet expected, ManifestDependencySet actual)
 {
     Assert.Equal(expected.TargetFramework, actual.TargetFramework);
     Assert.Equal(expected.Dependencies.Count, actual.Dependencies.Count);
     for (int i = 0; i < expected.Dependencies.Count; i++)
     {
         AssertDependency(expected.Dependencies[i], actual.Dependencies[i]);
     }
 }
Ejemplo n.º 4
0
        public override bool Execute()
        {
            var manifest     = Manifest.ReadFrom(new MemoryStream(File.ReadAllBytes(OriginalNuspec)), true);
            var assemblyFile = File.ReadAllText(AssemblyFile);

            manifest.Metadata.Version = Find(assemblyFile, "AssemblyInformationalVersion");
            NetPortableProfileTable.GetProfile("lol"); //prevent bug of concurrency on the table
            var tasks = Projects
                        .Select(i => System.Threading.Tasks.Task.Run(() =>
            {
                ProjectCollection collection = new ProjectCollection(new Dictionary <string, string>()
                {
                    { "Configuration", Configuration }
                });
                var project            = collection.LoadProject(i.ItemSpec);
                bool portable          = false;
                var prop               = project.AllEvaluatedProperties.OfType <ProjectProperty>().FirstOrDefault(b => b.Name == "TargetFrameworkProfile");
                string targetFramework = "net45";
                if (prop != null)
                {
                    targetFramework = FindMagicFreakingNugetString(prop.EvaluatedValue);
                    portable        = true;
                }
                Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
                var instance = project.CreateProjectInstance();
                var result   = new BuildManager().Build(new BuildParameters(), new BuildRequestData(instance, new string[] { "GetTargetPath" }));
                var dll      = result.ResultsByTarget.First(_ => _.Key == "GetTargetPath").Value.Items.First().ItemSpec;
                return(new
                {
                    Generated = dll,
                    PackageConfig = new PackageReferenceFile(Path.Combine(Path.GetDirectoryName(project.FullPath), "packages.config")),
                    TargetFramework = portable ? "portable-" + targetFramework : targetFramework,
                });
            })).ToArray();

            try
            {
                var projects = tasks.Select(t => t.Result).ToArray();
                foreach (var project in projects)
                {
                    var dependencies = new ManifestDependencySet();
                    manifest.Metadata.DependencySets.Add(dependencies);
                    dependencies.TargetFramework = project.TargetFramework;
                    dependencies.Dependencies    = new List <ManifestDependency>();
                    foreach (var dep in project.PackageConfig.GetPackageReferences())
                    {
                        dependencies.Dependencies.Add(new ManifestDependency()
                        {
                            Id      = dep.Id,
                            Version = dep.Version.ToString()
                        });
                    }
                    manifest.Files.Add(new ManifestFile()
                    {
                        Target = "lib\\" + project.TargetFramework,
                        Source = project.Generated
                    });
                }
                MemoryStream ms = new MemoryStream();
                manifest.Save(ms, true);
                ms.Position = 0;
                var result = new StreamReader(ms).ReadToEnd();
                File.WriteAllText(ModifiedNuspec, result);
            }
            catch (AggregateException aex)
            {
                ExceptionDispatchInfo.Capture(aex.InnerException).Throw();
            }
            return(true);
        }
Ejemplo n.º 5
0
        static Manifest InitiateManifestFromAssembly(Assembly assembly, IEnumerable <PackageReference> deps)
        {
            Manifest manifest = new Manifest();

            AssemblyInfo ainfo = new AssemblyInfo(assembly);

            //Version
            manifest.Metadata.Version = ManifestVersionFromAssembly(ainfo);

            // Copyright
            manifest.Metadata.Copyright = ainfo.Copyright;

            // Authors
            if (ainfo.Authors != null)
            {
                manifest.Metadata.Authors = ainfo.Authors.Keys.Aggregate((key, next) => key + "," + next);
                manifest.Metadata.Owners  = ainfo.Authors.Keys.Aggregate((key, next) => key + "," + next);
            }

            // Description
            manifest.Metadata.Description = ainfo.Description;

            // Icon Url
            if (ainfo.IconUrl != null)
            {
                manifest.Metadata.IconUrl = ainfo.IconUrl.ToString();
            }

            // Id
            manifest.Metadata.Id = ainfo.ProductTitle;

            // License Url
            if (ainfo.LicenseUrl != null)
            {
                manifest.Metadata.LicenseUrl = ainfo.LicenseUrl.ToString();
            }

            // Project Url
            if (ainfo.ProjectUrl != null)
            {
                manifest.Metadata.ProjectUrl = ainfo.ProjectUrl.ToString();
            }

            // Tags
            manifest.Metadata.Tags = ainfo.Tags;

            // Title
            manifest.Metadata.Title = ainfo.ProductTitle;

            // Dependencies
            if (deps != null)
            {
                manifest.Metadata.DependencySets = new List <ManifestDependencySet>();

                NetPortableProfile npp = new NetPortableProfile(ainfo.TargetFramework, new FrameworkName[1] {
                    new FrameworkName(ainfo.TargetFramework)
                });

                ManifestDependencySet mds = new ManifestDependencySet();
                mds.Dependencies    = new List <ManifestDependency>();
                mds.TargetFramework = npp.CustomProfileString;

                manifest.Metadata.DependencySets.Add(mds);
                foreach (var dep in deps)
                {
                    ManifestDependency md = new ManifestDependency();
                    md.Id      = dep.Id;
                    md.Version = dep.Version.ToNormalizedString();

                    mds.Dependencies.Add(md);
                }
            }

            return(manifest);
        }
Ejemplo n.º 6
0
 public void SetDependencies(ICollection<ManifestDependency> manifestDependencies, string targetFramework)
 {
     var manifestDependencySet = new ManifestDependencySet {Dependencies = manifestDependencies.ToList(), TargetFramework = targetFramework};
     _manifest.Metadata.DependencySets = new List<ManifestDependencySet>{ manifestDependencySet };
 }
        private static PackageDependencySet CreatePackageDependencySet(ManifestDependencySet manifestDependencySet)
        {
            FrameworkName targetFramework = manifestDependencySet.TargetFramework == null
                                            ? null
                                            : VersionUtility.ParseFrameworkName(manifestDependencySet.TargetFramework);

            var dependencies = from d in manifestDependencySet.Dependencies
                               select new PackageDependency(
                                   d.Id,
                                   String.IsNullOrEmpty(d.Version) ? null : VersionUtility.ParseVersionSpec(d.Version),
                                   d.Exclude);

            return new PackageDependencySet(targetFramework, dependencies);
        }