msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

MSBuild task with TargetFramework property broke in 17.3

Open MaceWindu opened this issue 3 years ago • 7 comments

Issue Description

We have following project configuration:

  • Project1 is C# analyzer project with TargetFrameworks=netstandard2.0
  • Project2 is multi-target project with TargetFrameworks=net48;net6.0 that also reference analyzers
  • msbuild target that calls MSBuild task for Project2 with TargetFramework=net48 as additional property

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 avatar Aug 17 '22 14:08 MaceWindu

As workaround we switched to dotnet build calls from Exec task

MaceWindu avatar Aug 17 '22 16:08 MaceWindu

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 avatar Aug 18 '22 17:08 benvillalobos

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

benvillalobos avatar Aug 18 '22 22:08 benvillalobos

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

MaceWindu avatar Aug 19 '22 11:08 MaceWindu

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.

oriches avatar Aug 26 '22 08:08 oriches

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)?

benvillalobos avatar Sep 01 '22 16:09 benvillalobos

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

MaceWindu avatar Sep 02 '22 08:09 MaceWindu

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

JanKrivanek avatar Apr 25 '23 16:04 JanKrivanek