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; }
/// <summary> /// Metedo que recursivamente recupera os artefatos que precisam constar no deploy /// </summary> /// <param name="projetosSolution">Lista com todos os projetos da solution</param> /// <param name="projetoAfetado">Projeto sendo analisado</param> /// <param name="artefatosDelta">Lista com os artefato delta com seus caminhos iniciando em apartir da primeira pasta dentro delta</param> /// <param name="caminhoInicioDeltaSolution">Diretorio da Solution em que o delta se encontra</param> /// <param name="projetosAfetados">Lista com os projetos afetados pelo delta</param> /// <param name="artefatosNecessarios">Lista de artefatos que precisam constar no deploy</param> private void RecuperaArtefatosRecursivo(List<Projeto> projetosSolution, Projeto projetoAfetado, List<string> artefatosDelta, string caminhoInicioDeltaSolution, List<Projeto> projetosAfetados, ref List<ObjetoDeploy> artefatosNecessarios) { if (projetosAfetados.Contains(projetoAfetado)) { artefatosNecessarios.Add(new ObjetoDeploy() { Arquivo = projetoAfetado.ArtefatoGerado, Binario = true }); artefatosNecessarios.AddRange(projetoAfetado.ArtefatosNaoCompiladosImportadosProjeto .Where(a => artefatosDelta .Contains(a.Replace(caminhoInicioDeltaSolution, string.Empty))) .Select(x => new ObjetoDeploy() { Arquivo = x, Binario = true })); } var projetosFilhos = projetosSolution.Where(x => projetoAfetado.ReferenciasProjeto.Contains(x.GUIDProjeto)); foreach (var projetoFilho in projetosFilhos) { RecuperaArtefatosRecursivo(projetosSolution, projetoFilho, artefatosDelta, caminhoInicioDeltaSolution, projetosAfetados, ref artefatosNecessarios); } }