I have an MsBuild task that I am writing, which works fine on my dev machine, but when I run it on our production environment, It cannot instantiate the SPFarm object ... even though the user I am logged on to the server as is a farm administrator.
The code below throws an error ...
using WSSAdmin = Microsoft.SharePoint.Administration;
WSSAdmin.SPFarm oFarm = WSSAdmin.SPFarm.Local;
if (oFarm == null)
{
throw new ApplicationException("Can't get Local SPFarm. Make sure you are member of 'Farm Admins' group");
}
Interestingly, if I run the code above from a simple command line application it works fine .... so I am (now) assuming that it is something to do with MsBuild ...
Can anyone suggest what I need to do to get this to run in MsBuild successfully?