Trump Talks for 28 Minutes on Bill Named for John McCain. Not Mentioned: McCain.

WASHINGTON — If President Trump had wanted to make a gracious mention of John McCain, the ailing Republican senator from Arizona, he could have done it on Monday, when the president signed the $716 billion military spending bill named in Mr. McCain’s honor.

He didn’t.

Standing in front of soldiers and senior military leaders at Fort Drum in New York, Mr. Trump made no mention of Mr. McCain, 81, who has been one of the president’s fiercest critics but has largely been absent from the Senate as he struggles with advanced brain cancer.

The president studiously avoided reading the official name of the legislation — which would have meant mentioning Mr. McCain — during the 28-minute speech or during the signing ceremony afterward. (The spending measure is officially called the John S. McCain National Defense Authorization Act for Fiscal Year 2019.)

Mr. Trump called it the “the most significant investment in our military, and our war fighters in modern history,” but did not make any reference to Mr. McCain’s military service or decades-long career fighting for the Pentagon budget.

The snub was not entirely unexpected. The president has repeatedly disparaged Mr. McCain, usually without using his name, even in the months since the senator has largely retreated from the Washington scene to his Arizona home for cancer treatment.

At a June rally, Mr. Trump criticized Mr. McCain for voting against a Republican bill to repeal the Affordable Care Act, saying that “one senator decided to put the thumb down, late in the morning. That was not a good thing when he put the thumb down.”

The president mocked him the same way during a speech to conservatives in February, prompting loud and angry boos from the audience at the reference to Mr. McCain. And just hours after signing the military spending bill on Monday, he did the same thing at a fund-raiser in upstate New York.

The relationship between the two men has never been good. As a candidate, Mr. Trump said he did not like Mr. McCain because the senator, a Navy pilot during the war in Vietnam, was shot down and captured, held for more than five years in a North Vietnamese prison and repeatedly tortured.

“He’s not a war hero,” Mr. Trump said at the time. “He’s a war hero because he was captured. I like people who weren’t captured.”

For his part, Mr. McCain has long been critical of Mr. Trump. When Mr. Trump was running for president, the senator criticized him for attacking Khizr Khan, the father of a fallen soldier. More recently, Mr. McCain issued a statement critical of Mr. Trump’s Helsinki summit meeting with President Vladimir V. Putin of Russia.

Mr. McCain called it “one of the most disgraceful performances by an American president in memory.”

During his three-decade career in the Senate, Mr. McCain has been a longtime supporter of the military. As chairman of the Senate Armed Services Committee, Mr. McCain was one of the most important voices in passing the vast military spending bill that Mr. Trump signed on Monday.