VSO 和 Azure 中的持续集成和 NuGet 恢复

Continuous integration AND NuGet restore in VSO and Azure

我们正在使用 VSO 和 Azure 云服务(网络角色)。

之前,我们使用以下 build.proj 文件作为 VSO 构建定义:

<?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>

这样做的原因是在 MSBuild 开始之前执行 NuGet 恢复 运行。这是 NuGet 的 suggested approach

现在我们正在尝试设置与我们的 Azure 云服务的持续集成,如 this MSDN article 中所述。

这意味着我们现在必须使用 TfvcContinuousDeploymentTemplate.12.xml 构建过程模板。

但是在设置模板构建build.proj文件时,出现如下构建错误:

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)

当使用 .sln 时,一切正常。但是我们显然还需要在构建之前进行 NuGet 恢复。

让持续集成和 NuGet 恢复工作的好的解决方案是什么?

我刚刚了解到这是多余的。没有理由手动执行 NuGet 恢复,因为它已经内置于 VSO/TFS.

阅读更多