在 Azure 管道 yml 中指定 framework/platform

Specify framework/platform in Azure pipeline yml

我想告诉 Azure 运行 针对我的测试项目实际使用的框架和平台进行测试。根据Microsoft

Tests that target the .NET core framework can be executed by specifying the appropriate target framework value.

但是我该怎么做呢?

此外,日志输出表明存在不同平台的问题。我也不确定如何解决这个问题。我试过在我的 yml 中加入一个平台,但没有用。

这是我当前的 yml:

- job: Test
  dependsOn: SetBuildName

  pool:
    vmImage: 'windows-2019'

  variables:
    solution: '**/MyTestSolution.sln'
    buildPlatform: 'x86|x64|ARM'
    buildConfiguration: 'Release'
    appxStagingDir: '$(build.artifactStagingDirectory)\AppxPackages\'

  steps:
  - task: NuGetToolInstaller@1
    inputs:
      versionSpec: '5.4.0'
  - task: NuGetCommand@2
    inputs:
      restoreSolution: '$(solution)'    

  - task: VersionAPPX@2
    inputs:
      Path: '$(Build.SourcesDirectory)'
      VersionNumber: '$(versionNumber)'
      InjectVersion: true
      OutputVersion: 'OutputedVersion'  

  - task: VSBuild@1
    inputs:
      platform: 'x86'   #Changing this to AnyCPU had no effect.
      solution: '$(solution)'
      configuration: '$(buildConfiguration)'
      msbuildArgs: '/t:Restore'

  - task: VSBuild@1
    inputs:
      platform: 'x86'
      solution: '$(solution)'
      configuration: '$(buildConfiguration)'
      msbuildArgs: '/p:AppxBundlePlatforms="$(buildPlatform)"
                    /p:AppxPackageDir="$(appxStagingDir)"
                    /p:AppxBundle=Always
                    /p:UapAppxPackageBuildMode=Sideload
                    /p:AppxPackageSigningEnabled=true
                    /p:VersionPrefix="$(versionNumber)"
                    /p:VersionSuffix="$(version.SpecialBuild)"
                    /p:SourceRevisionId="$(Build.SourceVersion)"'

这里是日志的摘录:

2020-03-19T12:28:57.5842598Z Test run will use DLL(s) built for framework .NETFramework,Version=v4.0 and platform X86. Following DLL(s) do not match framework/platform settings.
2020-03-19T12:28:57.5843802Z MyProject.Test.dll is built for Framework .NETCoreApp,Version=v3.1 and Platform AnyCPU.

最好的解决方案是告诉它使用项目构建所针对的任何内容。但如果那不可能,我会选择一种方法来指定 NETCoreApp 3.1 和 AnyCPU。

Tests that target the .NET core framework can be executed by specifying the appropriate target framework value.

VSTest@2任务中,有一个参数名称otherConsoleOptions。它可以向工具 vstest.console.exe 传递一些额外的选项,包括 platformframworketc.

注意:task 的 platfrom 参数仅用于 报告 目的。

这是我在 YAML 上使用的内容:

- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **\Release\UnitTestProject1.build.appxrecipe
      !**\*TestAdapter.dll
      !**\obj\**
    searchFolder: '$(System.DefaultWorkingDirectory)'
    otherConsoleOptions: '/Platform:x86 /Framework:Framework45'
    platform: 'x86|x64'

只需根据您的实际需求替换 otherConsoleOptions 值,如下所示:

otherConsoleOptions: '/Platform:{platform type: x86/x64/ARM} /Framework:{Framwork version}'

以上方法用于在yml文件中进行platform/framwork配置。

但是您可以使用另一种方法来实现它:在 runsetting file 中指定 platform typeframwork version

<RunSettings>
  <!-- Configurations that affect the Test Framework -->
  <RunConfiguration>
    ...
    ...
    <TargetPlatform>x86</TargetPlatform>
    <TargetFrameworkVersion>Framework40</TargetFrameworkVersion>
    ....
    ....
  </RunConfiguration>
  ...
...
</RunSettings>