private VisualStudioProjectNode CreateRoot(VisualStudioSolutionProject solutionProject,
                                                   string outputType, string rootNamespace, string targetFramework)
        {
            var node = new VisualStudioProjectNode
            {
                Name       = "Project",
                Attributes = new List <VisualStudioProjectNodeAttribute>
                {
                    new VisualStudioProjectNodeAttribute {
                        Name = "xmlns", Value = "http://schemas.microsoft.com/developer/msbuild/2003"
                    },
                    new VisualStudioProjectNodeAttribute {
                        Name = "DefaultTargets", Value = "Build"
                    },
                    new VisualStudioProjectNodeAttribute {
                        Name = "ToolsVersion", Value = "12.0"
                    }
                }
            };

            node.Children.Add(CreateImportCommonProps(node));
            node.Children.Add(CreatePropertyGroup(solutionProject, outputType, rootNamespace, targetFramework));

            return(node);
        }
        public void LoadProject(VisualStudioSolutionProject solutionProject)
        {
            if (solutionProject.TypeGuid == Guid.Parse(VisualStudioSolutionProjectTypeIds.SolutionFolderGuid))
            {
                return;
            }

            solutionProject.Project = _projectReader.ReadProject(solutionProject.QualifiedFileName);
        }
        private VisualStudioProjectNode CreatePropertyGroup(VisualStudioSolutionProject solutionProject,
                                                            string outputType, string rootNamespace, string targetFramework)
        {
            var node = new VisualStudioProjectNode
            {
                Name = "PropertyGroup"
            };

            node.Children.Add(new VisualStudioProjectNode
            {
                Name       = "Configuration",
                Value      = "Debug",
                Parent     = node,
                Attributes = new List <VisualStudioProjectNodeAttribute>
                {
                    new VisualStudioProjectNodeAttribute {
                        Name = "Condition", Value = " '$(Configuration)' == '' "
                    }
                }
            });
            node.Children.Add(new VisualStudioProjectNode
            {
                Name       = "Platform",
                Value      = "AnyCPU",
                Parent     = node,
                Attributes = new List <VisualStudioProjectNodeAttribute>
                {
                    new VisualStudioProjectNodeAttribute {
                        Name = "Condition", Value = " '$(Platform)' == '' "
                    }
                }
            });
            node.Children.Add(new VisualStudioProjectNode {
                Name = "ProjectGuid", Parent = node, Value = solutionProject.ProjectGuid.ToString("B").ToUpperInvariant()
            });
            node.Children.Add(new VisualStudioProjectNode {
                Name = "OutputType", Parent = node, Value = outputType
            });
            node.Children.Add(new VisualStudioProjectNode {
                Name = "AppDesignerFolder", Parent = node, Value = "Properties"
            });
            node.Children.Add(new VisualStudioProjectNode {
                Name = "RootNamespace", Parent = node, Value = rootNamespace
            });
            node.Children.Add(new VisualStudioProjectNode {
                Name = "AssemblyName", Parent = node, Value = rootNamespace
            });
            node.Children.Add(new VisualStudioProjectNode {
                Name = "TargetFrameworkVersion", Parent = node, Value = targetFramework
            });

            return(node);
        }
        public VisualStudioProject CreateNewProject(VisualStudioSolutionProject solutionProject,
                                                    string outputType, string rootNamespace, string targetFramework)
        {
            var project = new VisualStudioProject
            {
                ProjectFileName = solutionProject.FileName,
                Root            = CreateRoot(solutionProject, outputType, rootNamespace, targetFramework)
            };

            solutionProject.Project = project;

            return(project);
        }
        public void AddBuildTargets(VisualStudioSolutionProject solutionProject)
        {
            var root = solutionProject.Project.Root;

            if (solutionProject.TypeGuid == new Guid(VisualStudioSolutionProjectTypeIds.CsProjectGuid))
            {
                var node = root.Children.FirstOrDefault(n => n.Name.Equals("Import") && n.Attributes.Any(a => a.Name.Equals("Project") && a.Value.Equals("$(MSBuildToolsPath)\\Microsoft.CSharp.targets")));
                if (node != null)
                {
                    return;
                }

                int lastNodeIndex = -1;
                var lastNode      = root.Children.Last(n => n.Name.Equals("ItemGroup"));
                if (lastNode != null)
                {
                    root.Children.IndexOf(lastNode);
                }

                var targetsNode = new VisualStudioProjectNode
                {
                    Name       = "Import",
                    Parent     = root,
                    Attributes = new List <VisualStudioProjectNodeAttribute>
                    {
                        new VisualStudioProjectNodeAttribute {
                            Name = "Project", Value = "$(MSBuildToolsPath)\\Microsoft.CSharp.targets"
                        }
                    }
                };
                if (lastNodeIndex == -1)
                {
                    root.Children.Add(targetsNode);
                }
                else
                {
                    root.Children.Insert(lastNodeIndex + 1, targetsNode);
                }
            }
        }
 public void SaveProject(VisualStudioSolutionProject solutionProject)
 {
     _projectWriter.WriteProject(solutionProject.QualifiedFileName, solutionProject);
 }