Search code examples
azuremsbuildnugetazure-web-rolesbuild-definition

Continuous integration AND NuGet restore in VSO and Azure


We are using VSO and Azure Cloud Services (web roles).

Previously, we have used the following build.proj file for our VSO build definitions:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <OutDir>$(MSBuildThisFileDirectory)bin</OutDir>
    <Configuration>Release</Configuration>
    <ProjectProperties>OutDir=$(OutDir);Configuration=$(Configuration);</ProjectProperties>
  </PropertyGroup>
  <ItemGroup>
    <Solution Include="$(MSBuildThisFileDirectory)*.sln" />
  </ItemGroup>
  <Target Name="RestorePackages">
    <Exec Command="&quot;$(MSBuildThisFileDirectory).nuget\NuGet.exe&quot; restore &quot;%(Solution.Identity)&quot;" />
  </Target>
  <Target Name="Clean">
    <MSBuild Targets="Clean" Projects="@(Solution)" Properties="$(ProjectProperties)" />
  </Target>
  <Target Name="Build" DependsOnTargets="RestorePackages">
    <MSBuild Targets="Build" Projects="@(Solution)" Properties="$(ProjectProperties)" />
  </Target>
  <Target Name="Rebuild" DependsOnTargets="RestorePackages">
    <MSBuild Targets="Rebuild" Projects="@(Solution)" Properties="$(ProjectProperties)" />
  </Target>
</Project>

The reason for this is to execute NuGet restore before MSBuild began running. This is a suggested approach by NuGet.

Now that we are trying to set up continuous integration with our Azure cloud services, as instructed in this MSDN article.

This means that we must now use the TfvcContinuousDeploymentTemplate.12.xml build process template.

But when setting the template to build the build.proj file, the following build error occurs:

Exception Message: Deploying to Azure Cloud Service requires a Visual Studio Solution (.sln) that contains either a ccproj or a lsxproj. (type DeploymentException)
Exception Stack Trace:    at System.Activities.Statements.Throw.Execute(CodeActivityContext context)
   at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
   at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

When using the .sln, all works fine. But we obviously also need NuGet restore to occur before the build.

What is a good solution to have both continuous integration AND NuGet restore working?


Solution

  • I have just learnt that this is redundant. There is no reason to manually execute NuGet restore as this is already built into VSO/TFS.

    Read more here.