Esempio n. 1
0
        public static void ConvertToLinkProjectNetStd(SolutionMx slnMx,
                                                      string srcProject,
                                                      string autoGenFolder,
                                                      string targetFramework,
                                                      bool removeOriginalSrcProject)
        {
            SimpleNetStdProj netstdProj = new SimpleNetStdProj();

            netstdProj.SdkVersion      = "Microsoft.NET.Sdk";
            netstdProj.TargetFramework = targetFramework;
            //copy 'condition' nodes
            //------------------------------------
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(srcProject);


            netstdProj.AddPropertyGroups(SelectPropertyGroups(xmldoc.DocumentElement));

            List <XmlElement> compileNodes = SelectCompileNodes(xmldoc.DocumentElement);

            string onlyFileName     = Path.GetFileName(srcProject);
            string saveFileName     = slnMx.SolutionDir + "\\" + autoGenFolder + "\\" + onlyFileName;
            string targetSaveFolder = slnMx.SolutionDir + "\\" + autoGenFolder;

            //------------------------------------
            foreach (XmlElement elem in compileNodes)
            {
                XmlAttribute includeAttr = elem.GetAttributeNode("Include");

                netstdProj.AddCompileNode(
                    slnMx.BuildPathRelativeToOther(targetSaveFolder,
                                                   SolutionMx.CombineRelativePath(includeAttr.Value),
                                                   out string leftPart, out string rightPart),
                    //
                    rightPart
                    );
            }

            string targetSaveDir = System.IO.Path.GetDirectoryName(saveFileName);

            if (!Directory.Exists(targetSaveDir))
            {
                Directory.CreateDirectory(targetSaveDir);
            }

            //xmldoc.Save(saveFileName);
            netstdProj.Save(saveFileName);
            if (removeOriginalSrcProject)
            {
                File.Delete(srcProject);
            }
            //------------------------------------
        }
Esempio n. 2
0
        public static void ConvertToLinkProjectXamarin_droid(SolutionMx slnMx,
                                                             string srcProject,
                                                             string autoGenFolder,
                                                             string targetFramework,
                                                             bool removeOriginalSrcProject)
        {
            SimpleXamarin_MobileProj simpleXamarinProj = new SimpleXamarin_MobileProj(MobileProjPlatform.Android);
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(srcProject);
            XmlElement rootDoc = xmldoc.DocumentElement;

            List <XmlElement> compileNodes            = SelectCompileNodes(xmldoc.DocumentElement);
            string            onlyFileName            = Path.GetFileName(srcProject);
            string            onlyFilenameNoExtension = System.IO.Path.GetFileNameWithoutExtension(onlyFileName);


            string saveFileName     = slnMx.SolutionDir + "\\" + autoGenFolder + "\\" + onlyFileName;
            string targetSaveFolder = slnMx.SolutionDir + "\\" + autoGenFolder;



            //TODO: review here,
            //temp fix
            simpleXamarinProj.RootNamespace    =
                simpleXamarinProj.AssemblyName = onlyFilenameNoExtension + ".Droid";

            //simpleXamarinProj.DefineConstants = ";PIXEL_FARM; PIXEL_FARM_NET20; NET20; MINIMAL; GLES; WIN32; GL_ENABLE; SHARPZIPLIB;NETSTANDARD;";
            simpleXamarinProj.DefineConstants = ";PIXEL_FARM; PIXEL_FARM_NET20; NET20; GL_ENABLE; SHARPZIPLIB;NETSTANDARD;";

            foreach (XmlElement elem in compileNodes)
            {
                XmlAttribute      includeAttr = elem.GetAttributeNode("Include");
                SimpleCompileNode compileNode = new SimpleCompileNode();
                compileNode.Include = slnMx.BuildPathRelativeToOther(targetSaveFolder,
                                                                     SolutionMx.CombineRelativePath(includeAttr.Value),
                                                                     out string leftPart, out string rightPart);
                compileNode.Link = rightPart;
                simpleXamarinProj.AddCompileNode(compileNode);
            }

            string targetSaveDir = System.IO.Path.GetDirectoryName(saveFileName);

            if (!Directory.Exists(targetSaveDir))
            {
                Directory.CreateDirectory(targetSaveDir);
            }
            simpleXamarinProj.Save(saveFileName);

            //---

            File.Copy("AndroidManifest.xml", targetSaveFolder + "/AndroidManifest.xml", true);
        }
Esempio n. 3
0
        public static void ConvertToLinkProject2(SolutionMx slnMx, string srcProject, string autoGenFolder, bool removeOriginalSrcProject)
        {
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(srcProject);
            var    compileNodes     = SelectCompileNodes(xmldoc.DocumentElement);
            string onlyFileName     = Path.GetFileName(srcProject);
            string saveFileName     = slnMx.SolutionDir + "\\" + autoGenFolder + "\\" + onlyFileName;
            string targetSaveFolder = slnMx.SolutionDir + "\\" + autoGenFolder;
            string rightPart;

            string beginAt = slnMx.BuildPathRelativeToSolution(targetSaveFolder, out rightPart);

            foreach (XmlElement elem in compileNodes)
            {
                XmlAttribute includeAttr  = elem.GetAttributeNode("Include");
                string       includeValue = includeAttr.Value;
                string       combinedPath = SolutionMx.CombineRelativePath(includeValue);


                string b2 = slnMx.BuildPathRelativeToOther(targetSaveFolder, combinedPath, out rightPart);
                //this version:
                //auto gen project is lower than original 1 level
                //so change the original src location
                //and create linked child node
                includeAttr.Value = "..\\" + beginAt + rightPart;


                XmlElement linkNode = xmldoc.CreateElement("Link", elem.NamespaceURI);
                linkNode.InnerText = rightPart;
                elem.AppendChild(linkNode);
            }

            string targetSaveDir = System.IO.Path.GetDirectoryName(saveFileName);

            if (!Directory.Exists(targetSaveDir))
            {
                Directory.CreateDirectory(targetSaveDir);
            }

            xmldoc.Save(saveFileName);
            if (removeOriginalSrcProject)
            {
                File.Delete(srcProject);
            }
        }
Esempio n. 4
0
        public static void ConvertToLinkProject(SolutionMx slnMx, string srcProject, string autoGenFolder, bool removeOriginalSrcProject)
        {
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(srcProject);
            List <XmlElement> compileNodes     = SelectCompileNodes(xmldoc.DocumentElement);
            string            onlyFileName     = Path.GetFileName(srcProject);
            string            saveFileName     = slnMx.SolutionDir + "\\" + autoGenFolder + "\\" + onlyFileName;
            string            targetSaveFolder = slnMx.SolutionDir + "\\" + autoGenFolder;

            foreach (XmlElement elem in compileNodes)
            {
                XmlAttribute includeAttr = elem.GetAttributeNode("Include");

                includeAttr.Value = slnMx.BuildPathRelativeToOther(targetSaveFolder,
                                                                   SolutionMx.CombineRelativePath(includeAttr.Value),
                                                                   out string leftPart, out string rightPart);

                XmlElement linkNode = xmldoc.CreateElement("Link", elem.NamespaceURI);
                linkNode.InnerText = rightPart;
                elem.AppendChild(linkNode);
            }

            string targetSaveDir = System.IO.Path.GetDirectoryName(saveFileName);

            if (!Directory.Exists(targetSaveDir))
            {
                Directory.CreateDirectory(targetSaveDir);
            }

            xmldoc.Save(saveFileName);
            if (removeOriginalSrcProject)
            {
                File.Delete(srcProject);
            }
        }
Esempio n. 5
0
        public void MergeAndSave(string csprojFilename, string assemblyName, string targetFrameworkVersion, string additonalDefineConst, string[] references)
        {
            ProjectRootElement root = ProjectRootElement.Create();

            if (portable)
            {
                root.ToolsVersion   = "14.0";
                root.DefaultTargets = "Build";
                var import = root.AddImport(@"$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props");
                import.Condition = @"Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')";
            }
            else
            {
                root.AddImport(@"$(MSBuildToolsPath)\Microsoft.CSharp.targets");
            }
            ProjectPropertyGroupElement one1 = CreatePropertyGroup(root,
                                                                   targetFrameworkVersion,
                                                                   " '$(Configuration)' == '' ",
                                                                   " '$(Platform)' == '' ",
                                                                   "Debug", "AnyCPU", true, assemblyName);

            if (portable)
            {
                one1.AddProperty("MinimumVisualStudioVersion", "10.0");
                one1.AddProperty("ProjectTypeGuids", "{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}");
                one1.AddProperty("TargetFrameworkProfile", "Profile111");
            }

            ProjectPropertyGroupElement debugGroup = CreatePropertyGroupChoice(root,
                                                                               " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ",
                                                                               true,
                                                                               @"bin\Debug\", false, true, "full", "DEBUG; TRACE" + additonalDefineConst);
            ProjectPropertyGroupElement releaseGroup = CreatePropertyGroupChoice(root,
                                                                                 " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ",
                                                                                 true,
                                                                                 @"bin\Release\", true, false, "pdbonly", " TRACE" + additonalDefineConst);

            if (references.Length > 0)
            {
                AddItems(root, "Reference", references);
            }
            List <string>             allList        = new List <string>();
            Dictionary <string, bool> uniqueFileList = new Dictionary <string, bool>();
            string onlyProjPath       = Path.GetDirectoryName(csprojFilename) + "\\";
            int    onlyProjPathLength = onlyProjPath.Length;
            //TODO: review here
            //special for support .net20
            bool foundFirstExtensionAttributeFile = false;

            foreach (ToMergeProject toMergePro in subProjects)
            {
                List <string> allAbsFiles = toMergePro.GetAllAbsoluteFilenames();
                foreach (string filename in allAbsFiles)
                {
                    string onlyFileName = Path.GetFileName(filename);

                    if (onlyFileName == "PORTING_NOTMERGE.cs")
                    {
                        //our convention
                        continue;//skip
                    }
                    else if (onlyFileName == "ExtensionAttribute.cs")
                    {    //this is our convention
                         //... if we have ExtensionAttribute.cs
                         //the
                        if (foundFirstExtensionAttributeFile)
                        {
                            continue;
                        }
                        else
                        {
                            foundFirstExtensionAttributeFile = true;
                        }
                    }

                    string combindedFilename = SolutionMx.CombineRelativePath(filename).ToUpper();
                    if (uniqueFileList.ContainsKey(combindedFilename))
                    {
                        continue;
                    }
                    uniqueFileList[combindedFilename] = true;//
                    if (filename.StartsWith(onlyProjPath))
                    {
                        allList.Add(filename.Substring(onlyProjPathLength));
                    }
                    else
                    {
                        allList.Add(filename);
                    }
                }
            }
            // items to compile
            AddItems(root, "Compile", allList.ToArray());
            if (portable)
            {
                root.AddImport(@"$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets");
            }

            root.Save(csprojFilename);
        }