We consider the problem of distributed task assignment in a swarm of Unmanned Aerial Vehicles (UAVs), where heterogeneous agents that can have different capabilities need to work in teams to execute tasks. We consider the case where communication between UAVs is costly or dangerous and should be limited or avoided, while individual UAVs have uncertain and incomplete information at hand and new tasks can appear during the mission time. For this setting, we develop a distributed computing framework that allows for optimal task assignment under quite general conditions. At each time step of the scheme, each UAV can solve a local version of an optimisation problem that encodes the optimal task assignment for all UAVs. This optimisation problem takes the form of a mixed-integer linear programming problem (MILP) that can be solved readily with state-of-the-art solvers. Theoretical results ensuring the soundness of the proposed approach are reported and numerical results showing its efficacy are investigated.