Do you list a long-term visit as an affiliation (in a paper, presentation, etc.)?
I don't think that this question has a general answer as there might be guidelines applying to specific institutions.
I know of some institutions that explicitly require long-term visitors to state their affiliation. You should probably inquire about this with your institution. The institutions that I know that have rules about this usually require you to state your affiliation, and I have never seen a rule where you would be disallowed from doing that. So in any case, if a lot of the work has been carried out at the other institution and thus been taking advantage of their resources, an acknowledgement of that should probably be given in some way, whether it is in the form of a full affiliation, an affiliation with a footnote, or mentioning them in the acknowledgement section of the publication.