3

I have a powershell script which builds new TFS build definitions based on project. I use PowerGUI script editor to run the script and the script works perfectly. However, when I try to run the same script in Wondows PowerShell I get assembly loading errors.

new-object : Cannot find type [Microsoft.TeamFoundation.Client.TfsTeamProjectCollection]: make sure the assembly containing this type is loaded.

Why is this behavior occuring and what needs to be done in order to run the powershell script using WindowsPowerShell?

user1636380
  • 79
  • 1
  • 9

1 Answers1

3

That should be associated with this dll:

C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Client.dll

It should be in a similar location for VS 2010. One solution would be to use Add-Type to load it to the current session:

Add-Type -Path "$FilePath\Microsoft.TeamFoundation.Client.dll"

This solution may be preferable because your script will always check for that dll and it shouldn't break across environments. Your description of the problem makes it sound like the script is very dependent upon your environment, and relied on PowerGUI to execute correctly.

Depending on the version of the powershell console you're running, this question offers more suggestions for running assemblies from different versions of .NET. Your version of the Powershell console may have been compiled against a different version of .NET than the dll, and if that is the case you'll have to go to that question and follow the procedure to create a config file to make your console work with other versions of .NET. I would recommend using this answer as your example.

Community
  • 1
  • 1
Anthony Neace
  • 25,013
  • 7
  • 114
  • 129
  • Add-Type -Path "$FilePath\Microsoft.TeamFoundation.Client.dll" worked for me. I was loading assemblies in a different way and it worked with PowerGUI application but not with Windows PowerShell console. – user1636380 Aug 22 '13 at 15:49