The answer is yes, and it is really simple, thanks to this fantastic article by Jesse, that explains how to use Fiddler to being able to authenticate to on-premise TFS without the hassle of enabling basic authentication. Thanks to that article and Fiddler, you can simply login from tfx-cli to your TFS 2015 without any problem.
Figure 1: Login against your local TFS Service
Once I’m logged in, I can simply use the very same command used for VSTS to upload the directory where I defined the Build Task on my local TFS on-premise Server.
Figure 2: Task was uploaded to the server
As you can see the task was uploaded to the server, exactly in the very same way I uploaded to my VSTS account. The task is now available to be used in my TFS.
Figure 3: Custom task in action in a TFS 2015 on-premise build
Thanks to the extensibility with PowerShell I did not need to care about versions of VSTS or TFS, because the script does not have reference on any dll or package and the same task can be used both in VSTS or in TFS 2015 without changing a single line.
Thanks to the new Buidl System, extending a build for both VSTS and TFS is now a simple and easy task.