0
votes

I am seeing an issue when building in Azure DevOps on my own build VM. Same error occurs on a VS2017 hosted agent.

Building a csproj (happens when targeting the solution file too) of a .Net Framework 4.6.1 project. It has references to .Net Framework 4.6.1 projects.

In the build log I am seeing

1>C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1657,5): error : Project '..\MyNetFrameworkReferencedProject.csproj' targets 'netcoreapp2.1'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.6.1'. [C:\temp\vsts-2.150.2_work\10\s\TheNetFrameworkProjectIAmTryingToBuild.csproj ]

Here is my build step

enter image description here

The same error occurs 5 times for each other .Net Framework 4.6.1 project reference

Nothing in the erroring projects packages.json suggest they are targeting any netcore packages

Any idea what I should check next?

Edit --

Running with debugging on I am seeing this error

##[debug]Exit code: 1
##[debug]Error record:
##[debug]Invoke-VstsTool : Process 'msbuild.exe' exited with code '1'.
##[debug]At C:\temp\vsts-2.150.2\_work\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.151.0\ps_modules\MSBuildHelpers\InvokeFunctions.ps1:115 char:13
##[debug]+             Invoke-VstsTool -FileName $MSBuildPath -Arguments $argume ...
##[debug]+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##[debug]    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
##[debug]    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-VstsTool
##[debug] 
##[debug]Script stack trace:
##[debug]at Invoke-Tool, C:\temp\vsts-2.150.2\_work\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.151.0\ps_modules\VstsTaskSdk\ToolFunctions.ps1: line 110
##[debug]at Invoke-MSBuild, C:\temp\vsts-2.150.2\_work\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.151.0\ps_modules\MSBuildHelpers\InvokeFunctions.ps1: line 115
##[debug]at Invoke-BuildTools, C:\temp\vsts-2.150.2\_work\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.151.0\ps_modules\MSBuildHelpers\InvokeFunctions.ps1: line 38
##[debug]at <ScriptBlock>, C:\temp\vsts-2.150.2\_work\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.151.0\VSBuild.ps1: line 79
##[debug]at <ScriptBlock>, <No file>: line 1
##[debug]at <ScriptBlock>, <No file>: line 22
##[debug]at <ScriptBlock>, <No file>: line 18
##[debug]at <ScriptBlock>, <No file>: line 1
##[debug]Exception:
##[debug]Microsoft.PowerShell.Commands.WriteErrorException: Process 'msbuild.exe' exited with code '1'.
##[error]Process 'msbuild.exe' exited with code '1'.

I can take the MSBuild command minus the central logger and it will run successfully directly on the Build VM

"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild.exe" "C:\temp\vsts-2.150.2_work\10\s\MyProject.csproj" /nologo /nr:false /p:Version=0.1.31 /p:OutputPath="bin\release" /p:platform="any cpu" /p:configuration="release" /p:VisualStudioVersion="15.0" /m /p:_MSDeployUserAgent="VSTS_AGUID_build_9_0"

2
Is there something that is unclear about the error message? You have incompatible references.Daniel Mann
Hi @DanielMann, I appreciate the quick reply, is there an easy way to track them down? We are trying to move our builds to AZDO from TeamCity and have not seen this issue therebla9x
See my edit above, it is passing if I take the MSBuild command and run it directly on the VMbla9x
It's time to go home on Friday here but I think I may have uncovered the fix while tidying up another build The presence of a variable called "targetFramework" causes Nuget to use that as the target for restoring packages... 2019-05-17T04:41:05.6580899Z Restoring packages for .NETCoreApp,Version=v2.0... I will confirm and post some more details on Mondaybla9x

2 Answers

0
votes

You are referencing a .NET Core (netcoreapp2.1) project from a .NET Framework project, which is not possible.

If you want to share code between .NET Core and .NET Framework, change the referenced project to .NET Standard instead (change TargetFramework to netstandard2.0 in the csproj file).

0
votes

​I had a variable called "targetFramework" that I was using to track down where a Net Core API was being published as part of my build. The Nuget Restore task was picking up this variable and using it as a target and restoring the Net Core version of my packages.