dotnet / dotnet/msbuild

Microsoft.Build.Evaluation.Project doesnt work correctly when TargetFrameworks (extra s) property is defined

Open
#9,582 6 comments 0 reactions 0 assignees View on GitHub
Area: Documentation bug triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

### Issue Description

We are targetting our projects with multiple TFMs as net48 and net8.0. For that reason we have TargetFrameworks defined in project files instead of TargetFramework. TargetFramework property is not defined at all. Such projects compile just fine (two different binaries are produced) and VS is loading and showing those projects correctly as well. However we have additional tools which are internally using Microsoft.Build.Evaluation.Project instances and accessing collections like Items. If projects are defined with TargetFramework (no extra s) property. Such collection contains all items like compilation items (source files), content items etc. However when exactly same project is defined with TargetFrameworks (extra s), such collection no longer contains any of the items (compile, content etc.). And this is causing failure of our in-house tooling. It seems that when TargetFrameworks is defined, project is no longer handled as SDK style projects and none of the imports and logic works anymore for such projects. Small repro solution attached together with images of Items collection for both cases.

[TFMIssue.zip](https://github.com/dotnet/msbuild/files/13810616/TFMIssue.zip)
![TargetFramework](https://github.com/dotnet/msbuild/assets/4748314/1837e897-b8c3-42c5-a84e-7ea7f7c09774)
![TargetFrameworks](https://github.com/dotnet/msbuild/assets/4748314/cf0dd8a2-8c79-4ccc-9c18-06ea326c9673)

### Steps to Reproduce

Define project with TargetFRameworks property defined and TargetFramewok missing completely. Create instance of Microsoft.Build.Evaluation.Project by loading such project. Items collection (and similar) will not contain any compile, content etc items.
![TargetFrameworks](https://github.com/dotnet/msbuild/assets/4748314/baa95bc1-1042-4295-b0de-52e0bba85e43)

### Expected Behavior

When TargetFRamewoks property is defined (TargetFRamework missing). Instance of Microsoft.Build.Evaluation.Project should still provide compilation, content etc items in Items (and similar) collections.
![TargetFramework](https://github.com/dotnet/msbuild/assets/4748314/2262c0ba-1155-4091-94e1-3897e4ab7656)

### Actual Behavior

When TargetFRamewoks property is defined (TargetFRamework missing). Instance of Microsoft.Build.Evaluation.Project doesnt provide information's about compile, content etc items associated with project definition.

### Analysis

_No response_

### Versions & Configurations

Visual Studio 2022 17.8.3

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.