If Trump is actually serious about annexing Canada (or at least retaining the option), development of nuclear weapons would seem more likely to precipitate an invasion than to deter one.
Building nuclear weapons specifically to use against the US would also--in some measure, at least--justify any claims that such an invasion is a national security imperative.
Obviously these situations are quite a bit different.
Canada shares a border with the US and is an ocean away from anybody else.
DPRK is an ocean away from the US and shares borders with and enjoyed very credible security guarantees from both China and Russia. DPRK also shares a border with US ally South Korea, whose capital and millions of residents they already held at risk from thousands of hardened artillery positions and mobile launchers.
From what I understand, there were the usual half-arsed plans from the same stable geniuses who invaded Iraq. I've mostly been facetious, but honestly, the fact that you would consider a response to an idle invasion threat from a serially belligerent nation as itself being a threatening act - it's pretty indicative of the problem at hand.
I wouldn't consider it a threatening act. But I am not Commander in Chief of the US Armed Forces.
I am not advocating an invasion of Canada. I deplore the annexation rhetoric coming from POTUS. I don't believe there is a serious intention to annex Canada through military force, but I do believe loose talk like what we've seen harms our national security interests and understandably frightens our utterly vulnerable neighbors.
However, I also believe that in this new Great Game it's important to understand the actual state of the board and the likely actions/reactions of the other players.
Deluding oneself that Canada can resist a full-scale invasion by their only neighbor with overwhelming military, economic, industrial, financial, and diplomatic advantages because foreign nations will be obliged to join the war on Canada's side is unwise.
Deluding oneself that developing nuclear weapons would not be an easy casus belli for an actually hostile US is similarly unwise.
You're right, it's seeking and developing nuclear weapons that has been the problem historically. Once you have them it's fine, the sabre-rattling pretty much stops. Worked for India, Pakistan, China, North Korea.
Building nuclear weapons specifically to use against the US would also--in some measure, at least--justify any claims that such an invasion is a national security imperative.