Bill Cosby's decades-old jokes about using an aphrodisiac to seduce girls when he was a teenager cannot be used as evidence in his sex-assault trial, a Montgomery County judge ruled Friday.

Prosecutors can, however, use testimony from a 2005 deposition in which Cosby described obtaining Quaaludes to give to women he wanted to seduce,  Judge Steven T. O'Neill decided.

The ruling represented a partial win for the entertainer as prosecutors and defense lawyers try to shape the trial, scheduled to begin June 5 in Norristown.

In his one-page order, O'Neill rejected Montgomery County District Attorney Kevin R. Steele's request to show jurors excerpts from one of Cosby's books, in which he said he secretly sprinkled the aphrodisiac known as "Spanish Fly" on girls' cookies as a teenager.

"They're never in the mood for us. ... They need chemicals," Cosby told his friends, he wrote in the 1991 book, Childhood.

Prosecutors also wanted to include an interview on The Larry King Show in which Cosby joked with the talk show host about Spanish Fly.

Cosby's lawyers had objected, saying the reference was a joke about a mythical drug to teen boys, not evidence of a pattern of drugging women for sexual purposes.

O'Neill provided no reasoning in his ruling.

Cosby, 79, is charged with aggravated indecent assault for allegedly drugging and molesting former Temple University employee Andrea Constand at his Cheltenham home in 2004.

The entertainer has maintained his innocence, insisting that the interaction was consensual. His spokesman declined to comment on Friday's order, as did the prosecutor's office.

Constand sued Cosby in 2005, and his deposition testimony in that case included an admission that he had used Quaaludes to try to seduce women. He said he obtained seven prescriptions for Quaaludes in the 1970s.

"When you got the Quaaludes, was it in your mind that you were going to use these Quaaludes for young women that you wanted to have sex with?" asked Constand's lawyer, Dolores Troiani.

"Yes," Cosby responded.

Prosecutors have cited that testimony, made public in 2015, as the reason they reopened the criminal investigation against him.

O'Neill also ruled Friday that no evidence can be presented at trial about the settlement of Constand's civil lawsuit against Cosby.

The rulings resolved some of the last outstanding issues before the trial. Jury selection begins in Pittsburgh on May 22.