(CNN) — A 2005 deposition in which Bill Cosby admits to extramarital affairs and giving other women drugs with their consent so they’d have sex with him can be used by attorneys in a criminal case against him, a judge ruled Monday.

The deposition is from a civil case brought by Andrea Constand, who says Cosby drugged her and then sexually assaulted her. Cosby now faces criminal charges in the case.

Cosby attorneys said he only answered deposition questions because Bruce Castor, the district attorney at the time, promised to never bring a criminal case based on Constand’s allegations. Constand was a former employee at Cosby’s alma mater, Temple University.

Castor said he made that promise so the entertainer would not be able to use the Fifth Amendment to avoid answering questions in a deposition, according to an email from Castor to his successor, Risa Vetri Ferman. The civil suit was the best chance Constand had for finding justice, the Castor email said.

The current district attorney, Kevin Steele, responded in court documents that a formal nonprosecution agreement never existed, just a press release. He also said this kind of immunity can only be extended to a witness, not a defendant.

In issuing the order, Judge Steven O’Neill said a promise to not prosecute Cosby in the future did not exist based upon the evidence presented in court.

This is the first time Cosby has faced criminal prosecution. He is charged with three counts of felony aggravated indecent assault from a 2004 case involving Constand.

She said she went to his home in a Philadelphia suburb for a career consultation and he gave her a mix of pills and wine that left her incapacitated and unable to consent to sex.

The criminal case against Cosby is based partly on the 2005 deposition. In that testimony, he said the sexual encounter with Constand was consensual. Portions of that deposition were unsealed for the first time in 2015 after a lawsuit by The Associated Press that paved the way, prosecutors said, for re-opening the 2005 criminal investigation against Cosby in Pennsylvania.

In the deposition, Cosby said he had sexual relationships with at least five women outside his marriage, gave prescription sedatives to women he wanted to have sex with and tried to hide the affairs from his wife. He said he first met Constand at a Temple athletic facility when he showed her a back-relaxation technique, according to the deposition.

When asked how Cosby developed a romantic relationship with Constand, he said he acted as a mentor, by “inviting her to my house, talking to her about personal situations dealing with her life, growth, education access and thoughts to how to acquire a more aggressive attitude, protecting oneself in business,” according to the deposition.

In the current criminal case, Montgomery County’s district attorney has asked O’Neill to allow the testimony of 13 women who say Cosby drugged and sexually assaulted them from 1964 to 2002 to be included as evidence in the criminal case. O’Neill has not decided on the request. A hearing is scheduled for December 13 and 14.

The motion to show “prior bad acts of defendant” states, “what became clear was that the defendant has engaged, over the course of a lifetime, in a pattern of serial sexual abuse.” It does not name the women but provides their ages, when they met Cosby and how their relationship with Cosby developed.

Rule 404(b) of the Pennsylvania Rules of Evidence allows prosecutors to call witnesses about a defendant’s previous conduct if it is substantially similar to the trial at hand.

Cosby’s trial is scheduled to begin on June 5, 2017. He has pleaded not guilty to all charges.

Cosby’s team did not have a comment on the judge’s ruling.

CNN’s Ralph Ellis and Steve Forrest contributed to this report.