When you try to build a .NET6 solution using .NET7 as the latest installed version of SDK you may notice the below issue.
C:\Program Files\dotnet\sdk\7.0.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(376,5): error NETSDK1127: The targeting pack Microsoft.NETCore.App is not installed. Please restore and try again.
This issue is related to some variables that are not set properly and the right location for the tools cannot be determined although they are installed inside the operating system.
The task is using the default .NET runner of Teamcity and the default MSbuild version is set to Cross-platform MSBuild.
Switch to another version of MSBuild will most probably resolve the issue. For example in the setup I was working switching to MSBuild Tools 2022 removed the issue and build could be performed successfully.