dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.22k stars 1.35k forks source link

MSBuild task with TargetFramework property broke in 17.3 #7892

Open MaceWindu opened 2 years ago

MaceWindu commented 2 years ago

Issue Description

We have following project configuration:

After update to 17.3 build target start to fail with following error

C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5):
error NETSDK1005:
Assets file '...\MsBuildRegression\Analyzers\obj\project.assets.json'
doesn't have a target for 'netstandard2.0'.
Ensure that restore has run and that you have included 'netstandard2.0' in the TargetFrameworks for your project.
[...\MsBuildRegression\Analyzers\Analyzers.csproj]

Steps to Reproduce

MsBuildRegression.zip

In attached sample project invoke build-fails.cmd to get error.

build-works.cmd will run a task with TargetFrameworks=net48 which ~will pass~ fail too.

Expected Behavior

Specifying target framework for project doesn't affect target frameworks for referenced projects (or whatever happens here...)

Analysis

Versions & Configurations

MSBuild version 17.3.0+f67e3d35e for .NET Framework
17.3.0.37102
MaceWindu commented 2 years ago

As workaround we switched to dotnet build calls from Exec task

benvillalobos commented 2 years ago

I can successfully repro. Some questions:

What version of MSBuild did you update from?

Can you provide a binlog of the regressed scenario with the older version of MSBuild?

Did your version of the SDK change during this update?

benvillalobos commented 2 years ago

cc @dplaisted does this ring any bells/seem like an SDK issue?

MaceWindu commented 2 years ago

Yes, both SDK and MSBuild versions changed, but I made tests with older versions:

MSBUILD: Microsoft (R) Build Engine version 17.2.1+52cd2da31 for .NET Framework
From Visual Studio Build Tools 2022 17.2.6

- dotnet SDK: 6.0.302: Works
- dotnet SDK: 6.0.400:  Works

binlog msbuild.17.2.1.zip

After build tools update:

MSBuild version 17.3.0+f67e3d35e for .NET Framework
From Visual Studio Build Tools 2022 17.3.1

- dotnet SDK: 6.0.400:  Error

binlog msbuild.17.3.0.zip

oriches commented 2 years ago

Came across this thread whilst looking for answers....

I have a TeamCity build agent which was building perfectly fine with MS Build 17.1.0+ae57d105c but after update to MSBuild 17.3.1+2badb37d1 is now failing to build with error NETSDK1112.

Building win10-x64 app targetting .Net 6.0.

benvillalobos commented 2 years ago

Team Triage: There's an issue with the build.msbuild project. We noticed Targets="Restore;Build". Restore should happen in its own step, either by running msbuild /restore or create some restore target that calls the Restore target of the project you're trying to build. Let us know if it continues to fail afterward.

@oriches Can you file a separate issue with more details (logs, reproducible project)?

MaceWindu commented 2 years ago

Well, with two separate MSBuild tasks (one for restore and one for build) it works. Does it mean it is deliberate behavior change?

JanKrivanek commented 1 year ago

@MaceWindu this was side effect of previous changes. This currently doesn't meet bar for fixing - but we are leaving this open for upvotes.