That requires advice on your actual financial position and the current payment sequence. This guide does not recommend a universal sell-before-filing rule.
Coordinate rather than guess
Ask when funds would need to be available, how long the proposed transaction may take and what obligations a sale would create if immigration plans change. Verify the official instruction before making a programme payment. Neither a planned closing date nor available cash determines when permanent residence will be granted.
Coordinate rather than guess, and where the two processes cannot be coordinated, prefer the order that keeps options open. Selling early creates certainty about funds and gives up the asset, incurs the tax consequence, and exposes the applicant to holding cash through a period of unknown length. Selling late risks the funds not being available when required.
Neither is universally right, and the answer depends on the asset, the market, the applicant's other resources and how settled the immigration position is. What should be avoided is a sale executed on the assumption of a deadline that has not been confirmed from official materials. Establish what the actual requirement and timing are, take advice on the transaction, and then decide, keeping a record of the basis on which the decision was made.