【问题标题】:How to build unit test project when performing an Azure Cloud service CI build via Visual Studio Online?通过 Visual Studio Online 执行 Azure 云服务 CI 构建时如何构建单元测试项目?
【发布时间】:2014-10-25 20:06:50
【问题描述】:

我有一个包含以下项目的 Azure 云服务的 Visual Studio 解决方案:

  • 云服务
  • 云服务角色
  • 测试

Tests 项目是一个标准的 MSTest 项目,其中包含CloudServiceRole 项目中业务逻辑的单元测试。

代码存储在 Visual Studio Online 中,我已经连接了 Azure 提供的自动化 CI 构建部署。当我签入代码时,我的云服务的暂存部署会自动更新。但是,在 CI 构建期间甚至从未构建过 Tests 项目!当然,这意味着在构建过程中不会运行任何单元测试,因为构建过程的“运行单元测试”部分找不到带有测试的程序集。

我的目标是改变这一点,以便构建测试项目并执行所有单元测试。

查看 CI 部署过程使用的 MSBuild 参数,似乎只执行了 CloudService:Publish 目标。 CloudService 项目不依赖于 Tests 项目,因此 MSBuild 甚至从不构建后者。

我的尝试

我无法手动添加 CloudService->Tests 依赖项,因为当我在不是云服务角色项目的项目上添加依赖项时,我在构建过程中遇到错误 (The item "C:\a\src\MyProject\Tests\Tests.csproj" in item list "ProjectReferenceWithConfiguration" does not define a value for metadata "Name".) 并且我无法添加 CloudServiceRole->Tests 依赖项,因为那样会做一个循环依赖。

通过手动添加/t:Build 参数来指示MSBuild 构建完整解决方案导致另一个错误:C:\a\bin\ServiceDefinition.csdef: Need to specify the physical directory for the virtual path 'Web/' of role Web.

Tests 项目添加为单独的构建目标以及解决方案,会导致构建测试!但是,与此同时,它会禁用持续部署功能:More than one solution found. Continuous Deployment skipped.

尝试创建一个引用 Tests 项目但配置零实例的虚假云服务角色项目会导致构建错误:WAT100: The following roles 'Tests.FakeRole' have an instance count of 0. Instance count of 0 is not supported in deployments to Microsoft Azure。正在尝试禁用此验证results in a build error due to a defect in the Azure SDK

【问题讨论】:

    标签: azure msbuild azure-devops continuous-deployment azure-cloud-services


    【解决方案1】:

    您需要分别运行BuildPublish。我在我的 VSO(现在是 VSTS)项目中遇到了同样的问题,这解决了它。发生这种情况是因为您的云服务不依赖于您的单元测试项目。

    1) 带有参数 /t:Build 的 Visual Studio Build(或 MSBuild)操作(在此处清除)

    2) 带有参数 /t:Publish 的 Visual Studio Build(或 MSBuild)操作(此处不要清理)

    注意:我必须单独运行这些操作(不是 /Build;Publish),否则我会收到有关云服务入口点的错误。

    this questionherehere 拼凑而成。

    【讨论】:

      【解决方案2】:

      似乎带来结果的一种解决方法是将一个 pre-MSBuild 脚本添加到构建定义中,并在该脚本中显式构建 Tests 项目。

      :: This is used as a pre-build script in Continuous Deployment builds because on their own, they do not build the Tests project.
      "c:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" %~dp0\..\..\Tests\Tests.csproj /t:Build /p:Configuration=Debug;Platform=AnyCPU;OutDir="%~dp0\..\..\..\..\bin\\"
      

      它似乎可以完成这项工作,尽管我不确定我应该注意哪些副作用。我主要担心此构建中的二进制文件与云服务构建中的二进制文件进入同一目录 - 这里可能存在冲突的可能性吗?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-05
        • 1970-01-01
        相关资源
        最近更新 更多