visual studio - I cannot see my Message Text value in the build output with any verbosity - Stack Overflow

admin2025-04-17  4

I am trying to display a simple message in my build output window using the Message element and I am not seeing it in any verbosity setting. I can see the echo statement.

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

    <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net8.0-windows</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <UseWPF>true</UseWPF>
        <Deterministic>false</Deterministic>
        <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    </PropertyGroup>
    
    <Target Name="PostBuild" AfterTargets="PostBuildEvent">
      <Exec Command="echo hello world" />
    </Target>

    <Target Name="AfterBuild">
        <Message Text="Build completed successfully!" Importance="high" />
    </Target>
    
</Project>

Logs:

Rebuild started at 11:49 AM...
1>------ Rebuild All started: Project: WpfApp1, Configuration: Debug Any CPU ------
Restored C:\Users\user1\source\repos\PRACTICE\WpfApp1\WpfApp1\WpfApp1.csproj (in 2 ms).
1>WpfApp1 -> C:\Users\user1\source\repos\PRACTICE\WpfApp1\WpfApp1\bin\Debug\net8.0-windows\WpfApp1.dll
1>hello world
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
========== Rebuild completed at 11:49 AM and took 01.408 seconds ==========

I am trying to display a simple message in my build output window using the Message element and I am not seeing it in any verbosity setting. I can see the echo statement.

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

    <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net8.0-windows</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <UseWPF>true</UseWPF>
        <Deterministic>false</Deterministic>
        <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    </PropertyGroup>
    
    <Target Name="PostBuild" AfterTargets="PostBuildEvent">
      <Exec Command="echo hello world" />
    </Target>

    <Target Name="AfterBuild">
        <Message Text="Build completed successfully!" Importance="high" />
    </Target>
    
</Project>

Logs:

Rebuild started at 11:49 AM...
1>------ Rebuild All started: Project: WpfApp1, Configuration: Debug Any CPU ------
Restored C:\Users\user1\source\repos\PRACTICE\WpfApp1\WpfApp1\WpfApp1.csproj (in 2 ms).
1>WpfApp1 -> C:\Users\user1\source\repos\PRACTICE\WpfApp1\WpfApp1\bin\Debug\net8.0-windows\WpfApp1.dll
1>hello world
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
========== Rebuild completed at 11:49 AM and took 01.408 seconds ==========

Share edited Feb 9 at 23:07 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Feb 1 at 16:55 RodRod 15.5k35 gold badges134 silver badges264 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

There is already an AfterBuild task so your is getting overridden (only the last defined is used). Also define when you task should be called, so for example after the first one.

So the following should give you the output you want

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="echo hello world" />
</Target>

<Target Name="CustomAfterBuild" AfterTargets="PostBuild">
    <Message Text="Build completed successfully!" Importance="high" />
</Target>
...
1>hello world
1>Build completed successfully!
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
========== Rebuild completed at 19:59 and took 00,463 seconds ==========
转载请注明原文地址:http://anycun.com/QandA/1744822834a88104.html