Skip to content

What is the correct way to run a target before/after Restore? #5030

@tlmii

Description

@tlmii

Steps to reproduce

  1. Create a solution
  2. Add a project
  3. Edit the .csproj to add a target like
<Target Name="MyTarget" AfterTargets="Restore">
  <!-- Whatever you want it to do -->
</Target>
  1. From command line, run msbuild on your project, with restore and generate a binlog msbuild YourProjectName.csproj /r /bl
  2. Look at the msbuild.binlog file that's generated. MyTarget will be immediately after the Restore target.
  3. From command line, run msbuild on your solution with restore and generate a binlog msbuild YourSolutionName.sln /r /bl
  4. Look at the msbuild.binlog file that's generated. MyTarget will not be run at all.

Expected behavior

MyTarget target is run after Restore target.

Actual behavior

MyTarget target is never run

Environment data

msbuild /version output:

Microsoft (R) Build Engine version 16.5.0-preview-19562-03+d72e25031 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

16.5.0.56203

OS info:win

Other info

  1. The same thing is true for BeforeTargets as AfterTargets as far as I can tell.
  2. It looks like the problem is because there is no Restore target on the individual project when building from the solution. There is just one "meta" Restore target no matter how many projects are in the solution

Question

So the question then becomes, how do we do this properly? I want to do some extra restore stuff whenever a restore is done, but not worry about it at build time.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions