msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

[Feature Request]: Warns a user if they use Restore as an explicit target (/t:Restore;Build) instead of the /restore flag

Open baronfel opened this issue 1 year ago • 2 comments

Summary

We should warn users when they use the Restore target specifically (-t:Restore) instead of /restore during a build - this is very often a mistake and we should point users to the correct version.

Background and Motivation

Users of the new CLI-based MSBuild property/item syntax often run into issues with uninitialized repositories, so they add -t:Restore and then wonder why their tooling only works after the first run. This is the core reason, and we should guide them to using the switch.

Proposed Feature

When

  • Restore is part of the targets list, and
  • a project contains NuGet packages, and
  • a nuget dependency file was created during the build
  • then issue a warning so the user knows they should use /restore instead of /t:Restore

Alternative Designs

No response

baronfel avatar Jan 29 '24 15:01 baronfel

This is in the description but to be super clear: running just /t:Restore is ok; the problem is when you /t:Restore;Build (or similar), because of XML caches that may give the Build part a stale view of NuGet-generated MSBuild targets files.

rainersigwald avatar Jan 29 '24 16:01 rainersigwald

Related https://github.com/dotnet/msbuild/issues/9553 Pack is in the same boat here

JanKrivanek avatar Feb 16 '24 14:02 JanKrivanek