Anything that is technically within the boundaries of your property should be OK to build in, but there are some things you should keep in mind before building farm sheds or anything else that you want to build next to the boundary line for a neighbor's property. Here's some more detail on building sheds near boundary lines.
It's OK to build a shed right next to a fence or line, but you do have to make sure you stick to the right measurement for permitted development. Alternatively, you should get the right permit if you're building a larger shed with a larger plan. So, in other words, when it comes to the legality of the situation, you're OK as long as you stay within the lines and have all the right documentation.
However, even before considering your neighbor outside of the law, even if your initial build is legal, there are potential problems related to privacy if you're building it in such a way that your neighbor feels his privacy is infringed. Plus, the shed could potentially block their view of something that they object to as well.
Plus, it's possible that if a shed is built too closer to the fence you could have a build-up of the damp layer if the shed can't breathe and humidity builds up. On top of that, the shed could potentially cause other issues that could lead to damage.
Being a Good Neighbor
That said, there are other considerations besides just the legal. You're going to want to talk to your neighbor about your plans for the build-in case they have some objection to it and might prefer if you build in a different place.
For one thing, it's likely a good idea to leave a bit of a gap between the build and your fence just to avoid potential problems like damp build-up or overhang.
Overall though, the critical thing to do is get permission from your neighbor. If you just spring it on them, then a few things are likely to happen. For one, your relationship with your neighbor is going to have a tendency to sour. Secondly, you could end up fighting in court over it one way or another.
While you should be within your rights if you build within the lines, your neighbor could always challenge that. The last thing that you're going to want to happen is ending up in a protracted legal battle with a neighbor simply because you didn't ask them properly about the build.
You never know, they might be completely OK with it, or they might just have a few stipulations that might not be too big of a deal for you to complete. In the end, it's going to be well worth the effort to make sure your neighbor is onboard with the plan in terms of how much it might possibly avoid major problems later.
Being in court when you don't need to be is no fun as well as a waste of time and resources.