The class library outside your solution produces either an executable or dll, most likely a dll. When working with TeamCity, this dll is what you should be referencing in your project, rather than the external project itself.
If you are happy for the external library to build on your TeamCity Build Agents, add another Build Configuration to build the solution and post it as an artifact, you can then add a reference to your project to download this artifact into a known location and reference it directly. (for TeamCity build you can set it as an artifact dependency in the build configuration, for local builds I suggest you look into ways you can provide the external assembly automatically, I have not used Mercurial)
If this isn't going to work for you, your other option is to incorporate this library into the solution. Only do this if this is the only place the library is used! I am not advocating copying projects around your solutions, if its used in multiple locations then you need to provide it in a compatible way, as an artifact reference in TeamCity, and however best you find to provide the assembly for your local builds.