Freigeben über


A Simple Build Script for Packaging Visual Studio Extensions for Windows SharePoint Services (VSEWSS 1.3) Projects with Team Build

In a previous post, I provided a walkthrough for automating builds for VSEWSS 1.3 projects.  The script I used was based on the SharePoint Guidance Drop 11, and after using it, I felt it could be simplified.  I’m a proponent of implementing the “simplest possible thing that will work,” and the following build script contains the minimal functionality needed to automate the building and packaging of your SharePoint solutions.

 <?xml version="1.0" encoding="utf-8"?>
<Project xmlns="https://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">

  <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets" />

  <ProjectExtensions>
    <ProjectFileVersion>2</ProjectFileVersion>
  </ProjectExtensions>

  <PropertyGroup>
    <RunTest>false</RunTest>
    <RunCodeAnalysis>Never</RunCodeAnalysis>
    <SkipWorkItemCreation>true</SkipWorkItemCreation>
  </PropertyGroup>

  <PropertyGroup>
    <ContosoSolutionDir>c:\NightlyBuild\main\</ContosoSolutionDir>
    <ContosoSolutionName>Contoso.sln</ContosoSolutionName>
    <ContosoWSPName>Contoso.Deployment.wsp</ContosoWSPName>
    <ContosoDeploymentProjDir>c:\NightlyBuild\main\Contoso.Deployment\</ContosoDeploymentProjDir>
    <IDEPath>C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\</IDEPath>
  </PropertyGroup>
  
  <ItemGroup>
    <SolutionToBuild Include="$(BuildProjectFolderPath)/../../main/Contoso.sln">
    </SolutionToBuild>
  </ItemGroup>

  <ItemGroup>
    <ConfigurationToBuild Include="Debug|Any CPU">
      <FlavorToBuild>Debug</FlavorToBuild>
      <PlatformToBuild>Any CPU</PlatformToBuild>
    </ConfigurationToBuild>
  </ItemGroup>

  <Target Name="AfterCompile">
    
    <!-- The extensions modify files in the pkg directory, so those files cannot read only-->
    <BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Message="Making the pkg directory editable.">
      <Output TaskParameter="Id" PropertyName="StepId" />
    </BuildStep>
    <Exec Command="attrib -R &quot;$(ContosoDeploymentProjDir)pkg\*.*&quot; /S /D" />
    <BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Id="$(StepId)" Status="Succeeded" />

    <!-- Build using /package switch  -->
    <BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Message="Packaging wsp.">
      <Output TaskParameter="Id" PropertyName="StepId" />
    </BuildStep>
    <Exec Command="&quot;$(IDEPath)devenv&quot; &quot;$(ContosoSolutionDir)$(ContosoSolutionName)&quot; /Deploy debug /Package" />
    <BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Id="$(StepId)" Status="Succeeded" />

    <!-- Copy package to drop folder -->
    <BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Message="Copying wsp to drop folder.">
      <Output TaskParameter="Id" PropertyName="StepId" />
    </BuildStep>
    <Copy SourceFiles="$(ContosoDeploymentProjDir)bin\debug\$(ContosoWSPName)" DestinationFolder="$(DropLocation)\$(BuildNumber)" />
    <Copy SourceFiles="$(ContosoDeploymentProjDir)bin\debug\setup.bat" DestinationFolder="$(DropLocation)\$(BuildNumber)" />
    <BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Id="$(StepId)" Status="Succeeded" />

  </Target>
  
</Project>