glapointe / PowerShell-SPCmdlets

SharePoint 2010 and SharePoint 2013 custom PowerShell cmdlets.
Other
19 stars 3 forks source link

Missing reference assemblies causes exception in post build script GenerateHelp #2

Closed softwarecraft closed 9 years ago

softwarecraft commented 9 years ago

The post build script GenerateHelp.ps1 (when it calls the class Lapointe.PowerShell.MamlGenerator.CmdletHelpGenerator) requires the presence of two assemblies specific to the SharePoint version for each project:

The assemblies in the ReferenceAssemblies folder allow building (and packaging) the cmdlet projects on a dev or build machine without having either version of SharePoint installed. However, these two assemblies are missing from both projects' ReferenceAssemblies folder.

As a result, the Build-WSPs.ps1 script reports one of two errors on a dev or build machine that does not have the corresponding version of SharePoint installed, depending on which of these two assemblies is missing.

For example, for the Lapointe.SharePoint2010.PowerShell project:

GenerateHelp : Exception calling "GenerateHelp" with "3" argument(s): "Could not load file or assembly 'Microsoft.SharePoint.Library, Version=14.0.0.0, Cult ure=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The s ystem cannot find the file specified." At C:\Projects\Repos\Lapointe\PowerShell-SPCmdlets\Lapointe.SharePoint2010.Po werShell\GenerateHelp.ps1:20 char:70

  • [Lapointe.PowerShell.MamlGenerator.CmdletHelpGenerator]::GenerateHelp <<<< ($asm, "$path\POWERSHELL\Help", $true)
    • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    • FullyQualifiedErrorId : DotNetMethodException

or

GenerateHelp : Exception calling "GenerateHelp" with "3" argument(s): "Could not load file or assembly 'Microsoft.SharePoint.Client.ServerRuntime, Version=1 4.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its depend encies. The system cannot find the file specified." At C:\Projects\Repos\Lapointe\PowerShell-SPCmdlets\Lapointe.SharePoint2010.Po werShell\GenerateHelp.ps1:20 char:70

  • [Lapointe.PowerShell.MamlGenerator.CmdletHelpGenerator]::GenerateHelp <<<< ($asm, "$path\POWERSHELL\Help", $true)
    • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    • FullyQualifiedErrorId : DotNetMethodException

The solution is simple: ensure that these two assemblies can be found by the build engine. In keeping with the approach in this repo, add the two SharePoint version specific assemblies to each projects' ReferenceAssemblies folder.

Note, I'm fairly sure it is not permitted to redistribute Microsoft's SharePoint assemblies in this way. It would be more appropriate to provide a list of the required assemblies for the build and instructions on where to store them. On the other hand, there is definite value in having everything in place in the repo so it builds right away without any additional configuration.

For example, How to Build Office Developer Tools Projects with TFS Team Build 2012 explains how to set up a one-time global folder eg C:\Program Files\Reference Assemblies\Microsoft\SharePoint 2013\ and register this using a new registry key SharePoint 2013 under the branch HKEY_LOCAL_SYSTEM\SOFTWARE\Microsoft\.NETFramework\ v4.0.30319\AssemblyFoldersEx\. The equivalent for SharePoint 2010 is the registry branch HKEY_LOCAL_SYSTEM\SOFTWARE\Microsoft\.NETFramework\v2.0.50727\AssemblyFoldersEx.

According to How to: Add or Remove References By Using the Add Reference Dialog Box, the .NET framework version number in the registry branch is VersionMinimum, a lower bound value:

VersionMinimum is the lowest .NET Framework version that applies. If VersionMinimum is v3.0, folders specified in AssemblyFoldersEx apply to projects that target .NET Framework 3.0 and later.

So it might be more appropriate to use v3.5 and v4.5 for SharePoint 2010 and SharePoint 2013, respectively. I only tested it using the 4-part version number.

glapointe commented 9 years ago

I definitely think this approach would be much better. I didn't actually intend for the assemblies to get added to the repo - I just forgot to add an ignore for them (everything but the MAML assembly at least which I need to include with the project). I'll look into changing it to match this pattern. Thanks!

glapointe commented 9 years ago

I've updated the project files and the readme file with appropriate information. Thanks!