I want to tell Azure to run tests against the framework and platform actually used by my test project. According to Microsoft,
Tests that target the .NET core framework can be executed by specifying the appropriate target framework value.
But how do I do that?
Additionally, the log output says there is an issue of different platforms. I'm not sure how to address that either. I've tried putting a platform into my yml, but it doesn't help.
Here is my current 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)"'
And here is an excerpt from the log:
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.
The best solution would be to tell it to use whatever the project built against. But if that isn't possible, I'd settle for a way to specify NETCoreApp 3.1 and AnyCPU.
Tests that target the .NET core framework can be executed by specifying the appropriate target framework value.
In VSTest@2
task, there has one argument names otherConsoleOptions
. It can pass some additional options to the tool vstest.console.exe
, including platform, framwork and etc.
Note: The platfrom
argument of task just purely for reporting purposes.
Here is what I am using on my 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'
Just replace the otherConsoleOptions
value based on your actual demand like this:
otherConsoleOptions: '/Platform:{platform type: x86/x64/ARM} /Framework:{Framwork version}'
Above method is used for making platform/framwork
configuration in yml
file.
But there has another way you can use to achieve it: specify platform type
and framwork version
in your runsetting
file.
<RunSettings>
<!-- Configurations that affect the Test Framework -->
<RunConfiguration>
...
...
<TargetPlatform>x86</TargetPlatform>
<TargetFrameworkVersion>Framework40</TargetFrameworkVersion>
....
....
</RunConfiguration>
...
...
</RunSettings>