Reputation: 4916
I have a .NET solution that used to contain just .NET 5 applications. This compiled just fine using a YAML file on Azure DevOps.
However, since adding some .NET Framework 4.8 projects this now fails. I have read some articles that seem to explain the problem (to some extent) but the solution isn't clear to me. Perhaps someone could spell it out for me here?
In more detail...
I have the following mixture of projects:
The library is common to all. The .NET 4.8 WebAPI is referenced by the .NET 4.8 test suite, and the other .NET 5 test suites reference the .NET 5 WebAPI.
I have the following YAML file:
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildConfiguration: 'Release'
buildPlatform: 'Any CPU'
platform: x64
steps:
- task: NuGetCommand@2
displayName: 'Restore for all'
inputs:
restoreSolution: '$(solution)'
feedsToUse: 'select'
vstsFeed: '{Guid # 1}/{Guid # 2}'
- task: VSBuild@1
displayName: 'Build all'
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
maximumCpuCount: true
- task: DotNetCoreCLI@2
displayName: 'Run Tests'
inputs:
command: 'test'
projects: '**/*Test.csproj'
arguments: '--configuration $(buildConfiguration) --collect "Code coverage"'
We have a private NuGet gallery in the Azure Artifacts and the two Guids ({Guid # 1}/{Guid # 2}
) allow us to access that.
When this now executes, the following steps appear to succeed: Restore for all
and Build all
. However, the step that appears to fail is the Run Tests
.
The error message is:
##[error]Dotnet command failed with non-zero exit code on the following projects : D:\a\1\s\path\MySdkNet48.Test.csproj
This is the Test project that is .NET 4.8 and uses a SDK project file format.
Digging into the more verbose details in the Run Tests
step I see:
D:\a\1\s\path\MyNonSdkNet48WebApi.csproj(328,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\5.0.401\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\5.0.401\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" is correct, and that the file exists on disk.
##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1
and
##[error]Dotnet command failed with non-zero exit code on the following projects : D:\a\1\s\path\MySdkNet48Test.csproj
As mentioned above, I'm not clear on how to fix this...
Upvotes: 0
Views: 4323
Reputation: 114957
Since the 4.8 project isn't a Dotnet Core/5.0 project, it'll need to run using the Visual Studio Test task.
Split the test step in 2 separate steps, one configured to run the 4.8 projects, one to run the dotnet core/5.0 projects.
- task: DotNetCoreCLI@2
displayName: 'Run Tests'
inputs:
command: 'test'
projects: '**/*Test.csproj;!**/*48.Test.csproj'
arguments: '--configuration $(buildConfiguration) --collect "Code coverage"'
- task: VSTest@2
displayName: 'VsTest - testAssemblies'
inputs:
testAssemblyVer2: |
**\*48.Test.dll
Upvotes: 2