1

I am trying to run a command after build in my .net6.0 project, but I fail.

The .csproj file looks like this:

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

  <PropertyGroup>
    <TargetFramework>net6.0-windows</TargetFramework>
  </PropertyGroup>

  <Target Name="AfterBuild">
    <Message Text="hello world message"/>
    <Exec Command="echo hello world echo"/>
  </Target>

</Project>

I go to the folder containing the .csproj file, open cmd and type dotnet build. I get the following output (unfortunately German, so I translated it myself):

Microsoft (R)-Build-Engine, Version 17.0.0+c9eb9dd64 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to be restored...
  "C:\Users\...\MyProject.csproj" restored (in "59 ms").
  MyClass -> C:\Users\...\MyProject\bin\Debug\net6.0-windows\MyClass.dll

Build was successful.
    0 Warning(s)
    0 Error(s)

Elapsed time 00:00:02.12

So I get not output, neither from Message nor from Exec. What am I doing wrong?


I just started learning about targets in project files and wanted to try it out. Since it can't get any simpler than this, I have absolutely no idea what I should do now...

I even tried <Exec Command="mspaint"/> (which should open a new Paint window) in order to rule out that it's just an issue of output not getting into the right console. But it did not work either.

Kjara
  • 2,504
  • 15
  • 42
  • [This](https://stackoverflow.com/a/48069805/5333340) and [this](https://stackoverflow.com/a/43921993/5333340) answer my question(s) completely. – Kjara Jan 24 '22 at 13:57

0 Answers0