Exemple #1
0
        private Projeto RecuperaProjeto(string diretorioProjeto, string opcaoDeploy, string arquivoConfiguracoes)
        {
            string      csproj    = string.Empty;
            XmlDocument xmlCsproj = null;
            Projeto     retorno   = null;
            XmlNodeList auxNodes;
            XmlNode     auxNode;

            csproj = File.ReadAllText(diretorioProjeto);
            csproj = Infra.RemoveTagXmlTexto(csproj, " xmlns=\"");

            xmlCsproj = new XmlDocument();
            xmlCsproj.LoadXml(csproj);

            retorno = new Projeto();

            auxNode = xmlCsproj.SelectSingleNode("/Project/PropertyGroup/AssemblyName");

            retorno.ArtefatoGerado = auxNode.InnerText;

            auxNode = xmlCsproj.SelectSingleNode("/Project/PropertyGroup/ProjectGuid");

            retorno.GUIDProjeto = auxNode.InnerText;

            auxNode = xmlCsproj.SelectSingleNode("/Project/PropertyGroup/OutputType");

            switch (auxNode.InnerText)
            {
            case "Exe":
                retorno.TipoProjeto = Constantes.TipoProjeto.exe;
                break;

            case "Library":
                retorno.TipoProjeto = Constantes.TipoProjeto.dll;
                break;
            }

            auxNodes = xmlCsproj.SelectNodes("/Project/ItemGroup/Compile");

            if (auxNodes.Count > 0)
            {
                foreach (XmlNode node in auxNodes)
                {
                    retorno.ArtefatosCompiladosProjeto.Add(Infra.EncontraDiretorio(diretorioProjeto, node.Attributes["Include"].Value));
                }
            }

            auxNodes = xmlCsproj.SelectNodes("/Project/ItemGroup/Reference/HintPath");

            if (auxNodes.Count > 0)
            {
                foreach (XmlNode node in auxNodes)
                {
                    retorno.ArtefatosNaoCompiladosImportadosProjeto.Add(Infra.EncontraDiretorio(diretorioProjeto, node.InnerText));
                }
            }

            auxNodes = xmlCsproj.SelectNodes("/Project/ItemGroup/Content");

            if (auxNodes.Count > 0)
            {
                foreach (XmlNode node in auxNodes)
                {
                    retorno.ArtefatosNaoCompiladosProjeto.Add(Infra.EncontraDiretorio(diretorioProjeto, node.Attributes["Include"].Value));
                }
            }

            auxNodes = xmlCsproj.SelectNodes("/Project/ItemGroup/None");

            if (auxNodes.Count > 0)
            {
                foreach (XmlNode node in auxNodes)
                {
                    if (node.HasChildNodes &&
                        node.ChildNodes.Cast <XmlNode>().Where(x => x.Name == "SubType" && x.InnerText == "Designer").Any())
                    {
                        retorno.ArtefatosNaoCompiladosProjeto.Add(Infra.EncontraDiretorio(diretorioProjeto, node.Attributes["Include"].Value));
                    }
                }
            }

            auxNodes = xmlCsproj.SelectNodes("/Project/ItemGroup/ProjectReference/Project");

            if (auxNodes.Count > 0)
            {
                foreach (XmlNode node in auxNodes)
                {
                    retorno.ReferenciasProjeto.Add(node.InnerText.ToUpper());
                }
            }

            auxNodes = xmlCsproj.SelectNodes("/Project/PropertyGroup");

            var noTipoDeploy =
                auxNodes.Cast <XmlNode>()
                .Where(x =>
                       x.ChildNodes.Cast <XmlNode>()
                       .Any(a => a.Name == "OutputPath"))
                .Where(x =>
                       x.Attributes["Condition"].Value.Contains(opcaoDeploy))
                .ToList()
                .FirstOrDefault();

            if (noTipoDeploy != null)
            {
                XmlNode caminhoTipoDeploy = noTipoDeploy.ChildNodes.Cast <XmlNode>().Where(x => x.Name == "OutputPath").FirstOrDefault();

                retorno.ArtefatoGerado = Infra.EncontraDiretorio(diretorioProjeto, caminhoTipoDeploy.InnerText) + retorno.ArtefatoGerado + "." + retorno.TipoProjeto;
            }

            retorno.DiretorioProjeto = Path.GetDirectoryName(diretorioProjeto);

            retorno.ConfiguracaoDeploy = RecuperaConfiguracoesDeploy(retorno.DiretorioProjeto, retorno.DiretorioProjeto + Path.DirectorySeparatorChar + arquivoConfiguracoes);

            return(retorno);
        }