public static void ConvertCsproj(string path)
 {
     PackageVersions pv = new PackageVersions();
     HashSet<string> names = new HashSet<string>();
     string dir = path.Substring(0, path.LastIndexOf('/'));
     string input = File.ReadAllText(path);
     string output = "{\n  \"frameworks\": {\n    \"dnx451\": {\n      \"dependencies\": {\n";
     int idx = input.IndexOf("<Reference Include=\"");
     while (idx != -1)
     {
         int quote = input.IndexOf('\"', idx + 20);
         int comma = input.IndexOf(',', idx + 20);
         if ((comma != -1) && (comma < quote))
         {
             quote = comma;
         }
         string name = input.Substring(idx + 20, quote - idx - 20);
         if (!names.Contains(name))
         {
             names.Add(name);
             string version = pv.GetVersion(name.ToLower());
             if (version != null)
             {
                 output = output + "          \"" + name + "\": \"" + version + "\",\n";
             }
             else
             {
                 output = output + "          \"" + name + "\": \"\",\n";
             }
         }
         idx = input.IndexOf("<Reference Include=\"", quote);
     }
     output = output + "      }\n    }\n  }\n}";
     File.WriteAllText(dir + "/project.json", output);
 }
Esempio n. 2
0
        /// <summary>
        /// Convert .csproj files into DNX configuration files
        /// </summary>
        /// <param name="path">path to project folder</param>
        public static void ConvertCsproj(string path)
        {
            HashSet <string> names = new HashSet <string>();
            string           dir   = path.Substring(0, path.LastIndexOf('/'));

            if (!File.Exists(dir + "/project.json"))
            {
                //gac works correctly only in docker image
                string gac    = "/gac/v4.5/";
                string global = "";
                string input  = File.ReadAllText(path);
                string output = "{\n  \"frameworks\": {\n    \"dnx451\": {\n      \"dependencies\": {\n";
                int    idx    = input.IndexOf("<Reference Include=\"");
                while (idx != -1)
                {
                    int quote = input.IndexOf('\"', idx + 20);
                    int comma = input.IndexOf(',', idx + 20);
                    if ((comma != -1) && (comma < quote))
                    {
                        quote = comma;
                    }
                    string name = input.Substring(idx + 20, quote - idx - 20);
                    if ((name.IndexOf('$') == -1) && (name.IndexOf('\\') == -1) && !names.Contains(name))
                    {
                        names.Add(name);
                        string version = pv.GetVersion(name.ToLower());
                        if (version != null)
                        {
                            output = output + "          \"" + name + "\": \"" + version + "\",\n";
                        }
                        else
                        {
                            output = output + "          \"" + name + "\": \"\",\n";
                            if (File.Exists(gac + name + ".dll") && !name.Equals("mscorlib"))
                            {
                                global = global + gac + name + ".dll\n";
                            }
                        }
                    }
                    idx = input.IndexOf("<Reference Include=\"", quote);
                }
                output = output + "      }\n    }\n  }\n}";
                File.WriteAllText(dir + "/project.json", output);
                if (global.Length > 0)
                {
                    File.WriteAllText(dir + "/global.log", global);
                }
            }
        }
        public static void ConvertCsproj(string path)
        {
            PackageVersions  pv     = new PackageVersions();
            HashSet <string> names  = new HashSet <string>();
            string           dir    = path.Substring(0, path.LastIndexOf('/'));
            string           input  = File.ReadAllText(path);
            string           output = "{\n  \"frameworks\": {\n    \"dnx451\": {\n      \"dependencies\": {\n";
            int idx = input.IndexOf("<Reference Include=\"");

            while (idx != -1)
            {
                int quote = input.IndexOf('\"', idx + 20);
                int comma = input.IndexOf(',', idx + 20);
                if ((comma != -1) && (comma < quote))
                {
                    quote = comma;
                }
                string name = input.Substring(idx + 20, quote - idx - 20);
                if (!names.Contains(name))
                {
                    names.Add(name);
                    string version = pv.GetVersion(name.ToLower());
                    if (version != null)
                    {
                        output = output + "          \"" + name + "\": \"" + version + "\",\n";
                    }
                    else
                    {
                        output = output + "          \"" + name + "\": \"\",\n";
                    }
                }
                idx = input.IndexOf("<Reference Include=\"", quote);
            }
            output = output + "      }\n    }\n  }\n}";
            File.WriteAllText(dir + "/project.json", output);
        }