question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BeforeBuild/AfterBuild targets not honored.

See original GitHub issue

Steps to reproduce

Requires a project with the following

...
  <Target Name="BeforeBuild">
    <Message Text="Some message." />
  </Target>
...

Then

dotnet restore
dotnet build

Expected behavior

I expect the BeforeBuild target to be executed. Even adding BeforeTargets="Build" doesn’t work. Similarly for AfterBuild/DependsOnTargets="Build".

Actual behavior

The target isn’t run.

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-rc4-004771)

Product Information:
 Version:            1.0.0-rc4-004771
 Commit SHA-1 hash:  4228198f0e

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  14.04
 OS Platform: Linux
 RID:         ubuntu.14.04-x64
 Base Path:   /usr/share/dotnet/sdk/1.0.0-rc4-004771

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

22reactions
TheRealPiotrPcommented, Feb 27, 2017

Try this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard1.4</TargetFramework>
  </PropertyGroup>

  <Target Name="Foo"
          AfterTargets="Build">
    <Message Text="Bar" Importance="High" />
  </Target>

</Project>

The .NET Core SDK is not, AFAIK, bringing forward the BeforeBuild/AfterBuild extensibility model since the same behavior can be provided by MSBuild’s BeforeTargets/AfterTargets attributes, as exemplified above.

13reactions
george-chakhidzecommented, Jun 21, 2019

This one is also interesting: https://github.com/microsoft/msbuild/issues/1680#issuecomment-468710590

While <BeforeBuild> and <AfterBuild> do not work, oddly, these work fine:

<Target Name="CustomBeforeBuild" BeforeTargets="BeforeBuild" />
<Target Name="CustomAfterBuild" AfterTargets="AfterBuild" />
Read more comments on GitHub >

github_iconTop Results From Across the Web

Target BeforeBuild doesn't work in csproj
BeforeBuild dosen't working in csproj. That because Before/AfterTarget in csproj gets overridden by SDKs target file.
Read more >
Define a pre-build command without creating a new target
I'm struggling to define a fixed pre-build command for a target. ... I cannot immediately spot the problem without a working example.
Read more >
Extend the build process - MSBuild
The Visual Studio build process is defined by a series of MSBuild .targets files that are imported into your project file.
Read more >
Sencha Ext JS: Beyond ES5
It allows for configuring -before-build / -after-build targets (you can read more about it here). You can make use of delorean by configuring ......
Read more >
How do I run a script before compiling a project? - FAQ
Before compiling the project, I need to run the generate.sh or generate.bat script each time, which first compresses the file data and then ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found