コード例 #1
0
ファイル: Csproj.cs プロジェクト: tppApe/UfcppSample
        /// <summary>
        /// Rewrite this csproj file to migrate from packages.config and project.json to PackageReference tags:
        /// - Generate project.json
        /// - Remove {None Include="packages.confing"} and {None Include="project.json"}
        /// - Remove {References} reletated to NuGet packages
        /// - Add {PackageReference}
        /// - Change {Project} ToolsVersion attribute to 15.0
        /// - Remove packages.config and project.json files
        /// </summary>
        /// <returns>true if any change</returns>
        public bool MigrateToMsbuild15()
        {
            if (!HasPackagesConfig && !HasProjectJson)
            {
                return(false);
            }

            var packages1 = HasPackagesConfig ? PackagesConfig.Packages : Enumerable.Empty <Package>();
            var packages2 = HasProjectJson ? ProjectJson.Packages : Enumerable.Empty <Package>();
            var packages  = packages1.Concat(packages2);

            GeneratePackageReferences(packages);

            if (HasPackagesConfig)
            {
                foreach (var r in GetElementsInItemGroups("Reference"))
                {
                    if (PackagesConfig.Packages.Any(x => r.Attribute("Include").Value.StartsWith(x.Id + ",")))
                    {
                        r.Remove();
                    }
                }

                File.Delete(PackagesConfig.Path);
            }

            if (HasProjectJson)
            {
                File.Delete(ProjectJsonPath);

                var lockJsonPath = ProjectJsonPath.Replace(".json", ".lock.json");
                if (File.Exists(lockJsonPath))
                {
                    File.Delete(lockJsonPath);
                }
            }

            foreach (var n in GetElementsInItemGroups("None"))
            {
                var include = n.Attribute("Include");
                if (include.Value == PackagesConfName || include.Value == ProjectJsonName)
                {
                    n.Remove();
                }
            }

            var version = Content.Root.Attribute("ToolsVersion");

            version.Value = "15.0";

            return(true);
        }
コード例 #2
0
        public override bool Execute()
        {
            var fullPath = ProjectJsonPath.GetMetadata("FullPath");

            using (var reader = new StreamReader(fullPath))
            {
                var json = JObject.Parse(reader.ReadToEnd());
                PackageReferences = JsonConfigUtility.GetDependencies(json)
                                    .Select(ConvertToTaskItem)
                                    .ToArray();
            }

            return(true);
        }