dotnet / dotnet/msbuild

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

Open
#5,030 9 comments 9 reactions 0 assignees View on GitHub
question triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

### Steps to reproduce

1. Create a solution
2. Add a project
3. Edit the .csproj to add a target like

```

```

4. From command line, run msbuild on your project, with restore and generate a binlog `msbuild YourProjectName.csproj /r /bl`
5. Look at the msbuild.binlog file that's generated. MyTarget will be immediately after the Restore target.
6. From command line, run msbuild on your solution with restore and generate a binlog `msbuild YourSolutionName.sln /r /bl`
7. 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.

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.