The Rogers Cup event marks the 35-year-old Swiss star's first tuneup event for the US Open, which starts August 28, and will be his first visit to Montreal since 2011.
The Canadian hardcourt event alternates between Montreal and Toronto with a WTA event every year.
"I'm happy to be coming back to Montreal, as I have not had the chance to play there for many years," Federer said. "This 2017 season has been very exciting and I am really looking forward to being back on the court."
It also means Federer will celebrate his 36th birthday next Tuesday in Montreal.
"We are celebrating today and the celebrations will continue over the next few days, especially since Federer will celebrate his birthday with us on August 8," said tournament director Eugene Lapierre. "I'm certain the Montreal fans will give him the welcome he deserves."
Federer seeks his third crown in the Canadian event but the first in Montreal after 2004 and 2006 triumphs in Toronto.