Detecting when AVR ICSP header has a cable connected
How about this? When the board is powered from an external source, the D1 will prevent any voltage from appearing on ICSP VCC and R1 will ensure the line ICSP&nbsp;Present reads low.

When you plug in the programmer and it starts supplying power, the MCU will get power through the diode and ICSP Present will read high.

The 1K resistor is there just to limit the current that may flow through the GPIO ESD diodes.







simulate this circuit &ndash; Schematic created using CircuitLab



EDIT

The datasheet states that the voltage on the GPIOs should not exceed VCC by more than 0.5V, so you should to get a Schottky with a Vf &lt; 0.5V at whatever current your board requires.