There is a vast amount of publicly available bulk RNA-seq tumor samples paired with valuable information about clinical response to immunotherapies. It is now well established that the tumor microenvironment (TME) has a profound impact on the success of such therapies in multiple cancer types. However, a fundamental limitation of bulk RNA-seq analysis is the lack of consideration for cell-type composition. We previously developed xCell, a computational tool for estimating the cellular composition in bulk samples, which has been widely adopted. However, xCell relies on pre-defined references that has been optimized for identifying healthy cell-types. To accurately delineate the cellular composition of the TME, there is a need to train xCell for this task. Here we present xCell 2.0, a Bioconductor-compatible R package for cell-type enrichment analysis, which allows training on any bulk or single-cell RNA-seq datasets. xCell 2.0 provides the flexibility to tailor the cell-type enrichment analysis to specific use cases. We benchmarked xCell 2.0 on 25 different datasets using custom references from microarray, bulk, and single-cell RNA-seq data, and across different disease models. Our results suggest improved performance in comparison with the original version and other popular alternatives. Finally, we applied xCell 2.0 to a dataset of over 1,500 cancer patients pre-treated with immune checkpoint blockades to portray their TME, demonstrating its ability to predict the response to immunotherapies and provide valuable insights.