在Azure管道yml中指定框架/平台

问题描述 投票:0回答:1

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

可以通过指定适当的目标框架值来执行针对.NET核心框架的测试。

但是我该怎么做?

此外,日志输出显示存在不同平台的问题。我也不知道该如何解决。我曾尝试将平台放入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。

azure-devops azure-pipelines vstest
1个回答
1
投票

针对.NET核心框架的测试可以由指定适当的目标框架值。

VSTest@2任务中,有一个参数名称otherConsoleOptions。它可以将一些其他选项传递给工具vstest.console.exe,包括平台框架etc

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

这是我在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}'

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

但是还有另一种方法可以用来实现它:在platform type中指定framwork versionrunsetting file

runsetting
© www.soinside.com 2019 - 2024. All rights reserved.