Tuesday, January 11, 2011
Creating a SharePoint WSP package through Visual Studio 2010 Build
Essentially, with this approach the WSP will be created whenever you build your solution.
In a SharePoint projects project definition file or simply the project file (.csproj) couple of parameters are defined such as the build platform, build configuration etc. Apart from these variables the project file can be manually edited to add your own build tasks.
Build tasks are somewhat similar to targets in NAnt. They define a set of operations to execute during build. Visual Studio 2010 defines a set of standard SharePoint tasks that are defined in C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\SharePointTools\Microsoft.VisualStudio.SharePoint.targets. In this case I will be using the CreatePackage task.
First unload the SharePoint Project from Visual Studio to enable manual editing of the project file. Then select to edit the project file.
Scroll down right to the bottom and you will see the import of the SharePoint targets:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\SharePointTools\Microsoft.VisualStudio.SharePoint.targets" />
This imports the Microsoft.VisualStudio.SharePoint.targets MSBuild taget file to the project. We can override specific predefined targets defined in Microsoft.VisualStudio.SharePoint.targets
Right below add the following:
This appends the CreatePackage task to the existing tasks defined for BuildDependsOn. Now when you build the project the WSP will be created as well.
Here are some How To articles relevant to this: