Exemple #1
0
        public void BuildProjectFileCS2010(string Name, string Prefix)
        {
            XmlAttribute   Attr;
            XmlDocument    Doc;
            XmlDeclaration Dec;
            XmlElement     Element;
            XmlElement     ElementInner;
            XmlElement     ItemGroup;
            XmlElement     Project;
            XmlElement     PropertyGroup;



            //CodeName = Constant.Prefix & Constant.Root1 & "_" & strName
            Doc = new XmlDocument();
            Dec = Doc.CreateXmlDeclaration("1.0", "utf-8", null);
            Doc.AppendChild(Dec);
            Project        = Doc.CreateElement("Project");
            Attr           = Doc.CreateAttribute("ToolsVersion");
            Attr.InnerText = "4.0";
            Project.Attributes.Append(Attr);
            Attr           = Doc.CreateAttribute("DefaultTargets");
            Attr.InnerText = "Build";
            Project.Attributes.Append(Attr);
            Attr           = Doc.CreateAttribute("xmlns");
            Attr.InnerText = "http://schemas.microsoft.com/developer/msbuild/2003";
            Project.Attributes.Append(Attr);
            //Property Group
            PropertyGroup     = Doc.CreateElement("PropertyGroup");
            Element           = Doc.CreateElement("Configuration");
            Element.InnerText = "Debug";
            Attr           = Doc.CreateAttribute("Condition");
            Attr.InnerText = " '$(Configuration)' == '' ";
            Element.Attributes.Append(Attr);
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("Platform");
            Element.InnerText = "AnyCPU";
            Attr           = Doc.CreateAttribute("Condition");
            Attr.InnerText = " '$(Platform)' == '' ";
            Element.Attributes.Append(Attr);
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("ProductVersion");
            Element.InnerText = "8.0.30703";
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("SchemaVersion");
            Element.InnerText = "2.0";
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("ProjectGuid");
            Element.InnerText = _ProjectID.ToString();
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("OutputType");
            Element.InnerText = "WinExe";
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("RootNamespace");
            Element.InnerText = Name;
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("AssemblyName");
            Element.InnerText = Name;
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("TargetFrameworkVersion");
            Element.InnerText = "v4.0";
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("FileAlignment");
            Element.InnerText = "512";
            PropertyGroup.AppendChild(Element);
            Project.AppendChild(PropertyGroup);

            //Property Group Debug
            PropertyGroup  = Doc.CreateElement("PropertyGroup");
            Attr           = Doc.CreateAttribute("Condition");
            Attr.InnerText = " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ";
            PropertyGroup.Attributes.Append(Attr);
            Element           = Doc.CreateElement("DebugSymbols");
            Element.InnerText = "true";
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("DebugType");
            Element.InnerText = "full";
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("Optimize");
            Element.InnerText = "false";
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("OutputPath");
            Element.InnerText = _DevelopmentDirectory;
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("DefineConstants");
            Element.InnerText = "DEBUG;TRACE";
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("ErrorReport");
            Element.InnerText = "prompt";
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("WarningLevel");
            Element.InnerText = "4";
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("DocumentationFile");
            Element.InnerText = Name + Constant.xmlExtenstion;
            PropertyGroup.AppendChild(Element);
            Project.AppendChild(PropertyGroup);
            //Property Group Release
            PropertyGroup  = Doc.CreateElement("PropertyGroup");
            Attr           = Doc.CreateAttribute("Condition");
            Attr.InnerText = " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ";
            PropertyGroup.Attributes.Append(Attr);
            Element           = Doc.CreateElement("DebugType");
            Element.InnerText = "pdbonly";
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("Optimize");
            Element.InnerText = "true";
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("OutputPath");
            Element.InnerText = _DevelopmentDirectory;
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("DefineConstants");
            Element.InnerText = "TRACE";
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("ErrorReport");
            Element.InnerText = "prompt";
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("WarningLevel");
            Element.InnerText = "4";
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("DocumentationFile");
            Element.InnerText = Name + Constant.xmlExtenstion;
            PropertyGroup.AppendChild(Element);
            Project.AppendChild(PropertyGroup);

            //References
            ItemGroup      = Doc.CreateElement("ItemGroup");
            Element        = Doc.CreateElement("Reference");
            Attr           = Doc.CreateAttribute("Include");
            Attr.InnerText = "System";
            Element.Attributes.Append(Attr);
            ItemGroup.AppendChild(Element);
            Element        = Doc.CreateElement("Reference");
            Attr           = Doc.CreateAttribute("Include");
            Attr.InnerText = "System.Core";
            Element.Attributes.Append(Attr);
            ItemGroup.AppendChild(Element);
            Element        = Doc.CreateElement("Reference");
            Attr           = Doc.CreateAttribute("Include");
            Attr.InnerText = "System.Xml";
            Element.Attributes.Append(Attr);
            ItemGroup.AppendChild(Element);

            Element        = Doc.CreateElement("Reference");
            Attr           = Doc.CreateAttribute("Include");
            Attr.InnerText = "System.Drawing";
            Element.Attributes.Append(Attr);
            ItemGroup.AppendChild(Element);
            Element        = Doc.CreateElement("Reference");
            Attr           = Doc.CreateAttribute("Include");
            Attr.InnerText = "System.Windows.Forms";
            Element.Attributes.Append(Attr);
            ItemGroup.AppendChild(Element);

            Project.AppendChild(ItemGroup);

            ItemGroup = Doc.CreateElement("ItemGroup");
            foreach (CodeFile File in _Files)
            {
                switch (_Version)
                {
                case VS_Version.v2008:
                {
                    Element        = Doc.CreateElement("Compile");
                    Attr           = Doc.CreateAttribute("Include");
                    Attr.InnerText = File.Name;
                    Element.Attributes.Append(Attr);
                    ItemGroup.AppendChild(Element);
                    break;
                }

                case VS_Version.v2010:
                {
                    switch (File.Type)
                    {
                    case CodeFileType.Standard:
                    {
                        Element        = Doc.CreateElement("Compile");
                        Attr           = Doc.CreateAttribute("Include");
                        Attr.InnerText = File.Name;
                        Element.Attributes.Append(Attr);
                        ItemGroup.AppendChild(Element);
                        break;
                    }

                    case CodeFileType.Form:
                        Element        = Doc.CreateElement("Compile");
                        Attr           = Doc.CreateAttribute("Include");
                        Attr.InnerText = File.Name;
                        Element.Attributes.Append(Attr);
                        ElementInner           = Doc.CreateElement("SubType");
                        ElementInner.InnerText = "Form";
                        Element.AppendChild(ElementInner);
                        ItemGroup.AppendChild(Element);

                        //Designer
                        Element        = Doc.CreateElement("Compile");
                        Attr           = Doc.CreateAttribute("Include");
                        Attr.InnerText = File.Designer();
                        Element.Attributes.Append(Attr);
                        ElementInner           = Doc.CreateElement("DependentUpon");
                        ElementInner.InnerText = File.Name;
                        Element.AppendChild(ElementInner);
                        ItemGroup.AppendChild(Element);

                        //AssemblyInfo
                        Element        = Doc.CreateElement("Compile");
                        Attr           = Doc.CreateAttribute("Include");
                        Attr.InnerText = "Properties\\AssemblyInfo.cs";
                        Element.Attributes.Append(Attr);
                        ItemGroup.AppendChild(Element);
                        break;

                    case CodeFileType.Resource:
                        Project.AppendChild(ItemGroup);            //MAR *** Fix
                        ItemGroup      = Doc.CreateElement("ItemGroup");
                        Element        = Doc.CreateElement("EmbeddedResource");
                        Attr           = Doc.CreateAttribute("Include");
                        Attr.InnerText = File.Name;
                        Element.Attributes.Append(Attr);
                        ElementInner           = Doc.CreateElement("DependentUpon");
                        ElementInner.InnerText = File.Dependant;
                        Element.AppendChild(ElementInner);
                        ItemGroup.AppendChild(Element);
                        break;
                    }
                    //ItemGroup.AppendChild(Element);
                    break;
                }
                }
            }
            Project.AppendChild(ItemGroup);

            Element        = Doc.CreateElement("Import");
            Attr           = Doc.CreateAttribute("Project");
            Attr.InnerText = "$(MSBuildToolsPath)\\Microsoft.CSharp.targets";
            Element.Attributes.Append(Attr);
            Project.AppendChild(Element);

            Doc.AppendChild(Project);

            _ProjectFile = _Name + Constant.ExtensionProject(_Language);
            Doc.Save(Path + "\\" + _ProjectFile);
        }
Exemple #2
0
        public void BuildProjectFile(string Name)
        {
            XmlAttribute   Attr;
            XmlDocument    Doc;
            XmlDeclaration Dec;
            XmlElement     Element;
            XmlElement     ElementInner;
            string         FrameworkVersion = string.Empty;
            XmlElement     ItemGroup;
            string         MSBuild        = string.Empty;
            string         ProductVersion = string.Empty;
            XmlElement     Project;
            XmlElement     PropertyGroup;
            string         ToolsVersion = string.Empty;


            switch (_Language)
            {
            case LanguageType.CSharp:
                MSBuild = "CSharp";
                break;

            case LanguageType.VB:
                MSBuild = "VisualBasic";
                break;
            }

            switch (_Version)
            {
            case VS_Version.v2005:
                FrameworkVersion = "??";
                ToolsVersion     = "??";
                ProductVersion   = "??";
                break;

            case VS_Version.v2008:
                FrameworkVersion = "v3.5";
                ToolsVersion     = "3.5";
                ProductVersion   = "9.0.21022";
                break;

            case VS_Version.v2010:
                FrameworkVersion = "v4.0";
                ToolsVersion     = "4.0";
                ProductVersion   = "8.0.30703";
                break;
            }

            //CodeName = Constant.Prefix & Constant.Root1 & "_" & strName
            Doc = new XmlDocument();
            Dec = Doc.CreateXmlDeclaration("1.0", "utf-8", null);
            Doc.AppendChild(Dec);
            Project        = Doc.CreateElement("Project");
            Attr           = Doc.CreateAttribute("ToolsVersion");
            Attr.InnerText = ToolsVersion;
            Project.Attributes.Append(Attr);
            Attr           = Doc.CreateAttribute("xmlns");
            Attr.InnerText = "http://schemas.microsoft.com/developer/msbuild/2003";
            Project.Attributes.Append(Attr);
            //Property Group
            PropertyGroup     = Doc.CreateElement("PropertyGroup");
            Element           = Doc.CreateElement("Configuration");
            Element.InnerText = "Debug";
            Attr           = Doc.CreateAttribute("Condition");
            Attr.InnerText = " '$(Configuration)' == '' ";
            Element.Attributes.Append(Attr);
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("Platform");
            Element.InnerText = "AnyCPU";
            Attr           = Doc.CreateAttribute("Condition");
            Attr.InnerText = " '$(Platform)' == '' ";
            Element.Attributes.Append(Attr);
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("ProductVersion");
            Element.InnerText = ProductVersion;//"9.0.21022" maybe VS 2008 pro;
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("SchemaVersion");
            Element.InnerText = "2.0";
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("ProjectGuid");
            Element.InnerText = _ProjectID.ToString();
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("OutputType");
            Element.InnerText = "WinExe";
            PropertyGroup.AppendChild(Element);
            if (_Language == LanguageType.CSharp)
            {
                Element           = Doc.CreateElement("AppDesignerFolder");
                Element.InnerText = "Properties";
                PropertyGroup.AppendChild(Element);
            }
            Element           = Doc.CreateElement("RootNamespace");
            Element.InnerText = Name;
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("AssemblyName");
            Element.InnerText = Name;
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("FileAlignment");
            Element.InnerText = "512";
            PropertyGroup.AppendChild(Element);
            if (_Language == LanguageType.VB)
            {
                Element           = Doc.CreateElement("OptionExplicit");
                Element.InnerText = "On";
                PropertyGroup.AppendChild(Element);
                Element           = Doc.CreateElement("OptionCompare");
                Element.InnerText = "Binary";
                PropertyGroup.AppendChild(Element);
                Element           = Doc.CreateElement("OptionStrict");
                Element.InnerText = "On";
                PropertyGroup.AppendChild(Element);
                Element           = Doc.CreateElement("OptionInfer");
                Element.InnerText = "On";
                PropertyGroup.AppendChild(Element);
            }
            Element           = Doc.CreateElement("TargetFrameworkVersion");
            Element.InnerText = FrameworkVersion;
            PropertyGroup.AppendChild(Element);
            Project.AppendChild(PropertyGroup);

            //Property Group Debug
            PropertyGroup  = Doc.CreateElement("PropertyGroup");
            Attr           = Doc.CreateAttribute("Condition");
            Attr.InnerText = " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ";
            PropertyGroup.Attributes.Append(Attr);
            Element           = Doc.CreateElement("DebugSymbols");
            Element.InnerText = "true";
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("DebugType");
            Element.InnerText = "full";
            PropertyGroup.AppendChild(Element);
            if (_Language == LanguageType.CSharp)
            {
                Element           = Doc.CreateElement("Optimize");
                Element.InnerText = "false";
                PropertyGroup.AppendChild(Element);
            }
            else
            {
                Element           = Doc.CreateElement("DefineDebug");
                Element.InnerText = "true";
                PropertyGroup.AppendChild(Element);
                Element           = Doc.CreateElement("DefineTrace");
                Element.InnerText = "true";
                PropertyGroup.AppendChild(Element);
            }
            Element           = Doc.CreateElement("OutputPath");
            Element.InnerText = "bin\\Debug\\";
            PropertyGroup.AppendChild(Element);
            //Element = Doc.CreateElement("DocumentationFile");
            //Element.InnerText = Name + Constant.xmlExtenstion;
            //PropertyGroup.AppendChild(Element);
            if (_Language == LanguageType.CSharp)
            {
                Element           = Doc.CreateElement("DefineConstants");
                Element.InnerText = "DEBUG;TRACE";
                PropertyGroup.AppendChild(Element);
                Element           = Doc.CreateElement("ErrorReport");
                Element.InnerText = "prompt";
                PropertyGroup.AppendChild(Element);
                Element           = Doc.CreateElement("WarningLevel");
                Element.InnerText = "4";
                PropertyGroup.AppendChild(Element);
            }
            else
            {
                Element           = Doc.CreateElement("NoWarn");
                Element.InnerText = string.Empty;
                PropertyGroup.AppendChild(Element);
                Element           = Doc.CreateElement("WarningsAsErrors");
                Element.InnerText = "41999,42016,42017,42018,42019,42020,42021,42022,42032,42036";
                PropertyGroup.AppendChild(Element);
            }
            Project.AppendChild(PropertyGroup);
            //Property Group Release
            PropertyGroup  = Doc.CreateElement("PropertyGroup");
            Attr           = Doc.CreateAttribute("Condition");
            Attr.InnerText = " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ";
            PropertyGroup.Attributes.Append(Attr);
            Element           = Doc.CreateElement("DebugType");
            Element.InnerText = "pdbonly";
            PropertyGroup.AppendChild(Element);
            if (_Language == LanguageType.VB)
            {
                Element           = Doc.CreateElement("DefineDebug");
                Element.InnerText = "false";
                PropertyGroup.AppendChild(Element);
                Element           = Doc.CreateElement("DefineTrace");
                Element.InnerText = "true";
                PropertyGroup.AppendChild(Element);
            }
            Element           = Doc.CreateElement("Optimize");
            Element.InnerText = "true";
            PropertyGroup.AppendChild(Element);
            Element           = Doc.CreateElement("OutputPath");
            Element.InnerText = "bin\\Release\\";
            PropertyGroup.AppendChild(Element);
            //Element = Doc.CreateElement("DocumentationFile");
            //Element.InnerText = Name + Constant.xmlExtenstion;
            //PropertyGroup.AppendChild(Element);
            if (_Language == LanguageType.CSharp)
            {
                Element           = Doc.CreateElement("DefineConstants");
                Element.InnerText = "TRACE";
                PropertyGroup.AppendChild(Element);
                Element           = Doc.CreateElement("ErrorReport");
                Element.InnerText = "prompt";
                PropertyGroup.AppendChild(Element);
                Element           = Doc.CreateElement("WarningLevel");
                Element.InnerText = "4";
                PropertyGroup.AppendChild(Element);
            }
            else
            {
                Element           = Doc.CreateElement("NoWarn");
                Element.InnerText = string.Empty;
                PropertyGroup.AppendChild(Element);
                Element           = Doc.CreateElement("WarningsAsErrors");
                Element.InnerText = "41999,42016,42017,42018,42019,42020,42021,42022,42032,42036";
                PropertyGroup.AppendChild(Element);
            }
            Project.AppendChild(PropertyGroup);

            //Program
            PropertyGroup     = Doc.CreateElement("PropertyGroup");
            Element           = Doc.CreateElement("StartupObject");
            Element.InnerText = Name + ".Program";
            PropertyGroup.AppendChild(Element);
            Project.AppendChild(PropertyGroup);

            //References
            ItemGroup      = Doc.CreateElement("ItemGroup");
            Element        = Doc.CreateElement("Reference");
            Attr           = Doc.CreateAttribute("Include");
            Attr.InnerText = "System";
            Element.Attributes.Append(Attr);
            ItemGroup.AppendChild(Element);
            Element        = Doc.CreateElement("Reference");
            Attr           = Doc.CreateAttribute("Include");
            Attr.InnerText = "System.Core";
            Element.Attributes.Append(Attr);
            ItemGroup.AppendChild(Element);
            Element        = Doc.CreateElement("Reference");
            Attr           = Doc.CreateAttribute("Include");
            Attr.InnerText = "System.Xml";
            Element.Attributes.Append(Attr);
            ItemGroup.AppendChild(Element);
            if (_Language == LanguageType.CSharp)
            {
                Element        = Doc.CreateElement("Reference");
                Attr           = Doc.CreateAttribute("Include");
                Attr.InnerText = "Microsoft.CSharp";
                Element.Attributes.Append(Attr);
                ItemGroup.AppendChild(Element);
            }

            Element        = Doc.CreateElement("Reference");
            Attr           = Doc.CreateAttribute("Include");
            Attr.InnerText = "System.Drawing";
            Element.Attributes.Append(Attr);
            ItemGroup.AppendChild(Element);
            Element        = Doc.CreateElement("Reference");
            Attr           = Doc.CreateAttribute("Include");
            Attr.InnerText = "System.Windows.Forms";
            Element.Attributes.Append(Attr);
            ItemGroup.AppendChild(Element);

            Project.AppendChild(ItemGroup);

            ItemGroup = Doc.CreateElement("ItemGroup");
            foreach (CodeFile File in _Files)
            {
                switch (File.Type)
                {
                case CodeFileType.Standard:
                {
                    Element        = Doc.CreateElement("Compile");
                    Attr           = Doc.CreateAttribute("Include");
                    Attr.InnerText = File.Name;
                    Element.Attributes.Append(Attr);
                    ItemGroup.AppendChild(Element);
                    break;
                }

                case CodeFileType.Program:
                {
                    Element        = Doc.CreateElement("Compile");
                    Attr           = Doc.CreateAttribute("Include");
                    Attr.InnerText = File.Name;
                    Element.Attributes.Append(Attr);
                    ItemGroup.AppendChild(Element);
                    break;
                }

                case CodeFileType.Form:
                    Element        = Doc.CreateElement("Compile");
                    Attr           = Doc.CreateAttribute("Include");
                    Attr.InnerText = File.Name;
                    Element.Attributes.Append(Attr);
                    ElementInner           = Doc.CreateElement("SubType");
                    ElementInner.InnerText = "Form";
                    Element.AppendChild(ElementInner);
                    ItemGroup.AppendChild(Element);

                    //Designer
                    Element        = Doc.CreateElement("Compile");
                    Attr           = Doc.CreateAttribute("Include");
                    Attr.InnerText = File.Designer();
                    Element.Attributes.Append(Attr);
                    //ElementInner = Doc.CreateElement("SubType");
                    //ElementInner.InnerText = "Code";
                    //Element.AppendChild(ElementInner);
                    ElementInner           = Doc.CreateElement("DependentUpon");
                    ElementInner.InnerText = File.Name;
                    Element.AppendChild(ElementInner);
                    ItemGroup.AppendChild(Element);

                    //AssemblyInfo
                    Element        = Doc.CreateElement("Compile");
                    Attr           = Doc.CreateAttribute("Include");
                    Attr.InnerText = Constant.AuxilleryDirectory(_Language) + "\\AssemblyInfo" + Constant.ExtensionFile(_Language);
                    Element.Attributes.Append(Attr);
                    ItemGroup.AppendChild(Element);
                    break;

                case CodeFileType.Resource:
                    if ((int)_Version < (int)VS_Version.v2010)
                    {
                        Project.AppendChild(ItemGroup);
                        ItemGroup = Doc.CreateElement("ItemGroup");
                    }
                    Element        = Doc.CreateElement("EmbeddedResource");
                    Attr           = Doc.CreateAttribute("Include");
                    Attr.InnerText = File.Name;
                    Element.Attributes.Append(Attr);
                    ElementInner           = Doc.CreateElement("DependentUpon");
                    ElementInner.InnerText = File.Dependant;
                    Element.AppendChild(ElementInner);
                    ItemGroup.AppendChild(Element);
                    break;

                    //<ItemGroup>
                    //  <None Include="Resources\StatusIcon.bmp" />
                    //</ItemGroup>
                }
                //ItemGroup.AppendChild(Element);
            }
            Project.AppendChild(ItemGroup);

            Element        = Doc.CreateElement("Import");
            Attr           = Doc.CreateAttribute("Project");
            Attr.InnerText = "$(MSBuildToolsPath)\\Microsoft." + MSBuild + ".targets";
            Element.Attributes.Append(Attr);
            Project.AppendChild(Element);

            Doc.AppendChild(Project);

            _ProjectFile = _Name + Constant.ExtensionProject(_Language);
            Doc.Save(Path + "\\" + _ProjectFile);
        }