2

I've added some additional targets to a .csproj file in order to carry out some additional tasks after the project build is completed.

Nothing appears in the Visual Studio output window until all targets have completed. I want to be able to see messages that occur as the targets are being processed.

If I use the MSBuild Task Explorer (a VS extension), I can see that the messages can be picked up by a Visual Studio window as they are generated, so am I just missing a setting somewhere?

I've also tried replacing the Exec tasks with SmartExec from the MSBuild Extensions package.

Here is a snippet from my .csproj project file:

<Target Name="PostBuildActions" AfterTargets="Build">
<!--Get the version number from the assembly info -->
<GetAssemblyIdentity AssemblyFiles="$(ProjectDir)$(OutputPath)$(TargetFileName)">
  <Output TaskParameter="Assemblies" ItemName="ToolboxVersion" />
</GetAssemblyIdentity>
<CreateProperty Value="$(ProjectDir)$(OutputPath.TrimEnd('\'))">
  <Output TaskParameter="Value" PropertyName="ToolboxTarget" />
</CreateProperty>
<!-- Run the Simulink Widget Generator tool -->
<CreateProperty Value="&quot;$(SolutionDir)SimulinkWidgetGenerator\bin\$(Configuration)\SimulinkWidgetGenerator.exe&quot; -v %(ToolboxVersion.Version) -d &quot;$(ToolboxTarget)&quot;">
  <Output TaskParameter="Value" PropertyName="WidgetGenCommand" />
</CreateProperty>
<Message Text="Running Simulink Widget Generator:" Importance="High" />
<Message Text="$(WidgetGenCommand)" Importance="High" />
<Exec Command="$(WidgetGenCommand)" ConsoleToMSBuild="true" />
<!-- Invoke Matlab -->
<CreateProperty Value="try, PackageToolbox, catch ex, disp(getReport(ex)), exit(-1), end, exit(0);">
  <Output TaskParameter="Value" PropertyName="MatlabScript" />
</CreateProperty>
<CreateProperty Value="&quot;$(MATLAB_INSTALL_DIR)\bin\matlab.exe&quot; -automation -wait -log -sd &quot;$(ToolboxTarget)&quot; -r &quot;$(MatlabScript)&quot;">
  <Output TaskParameter="Value" PropertyName="MatlabCommand" />
</CreateProperty>
<Message Text="Invoking Matlab: " Importance="High" />
<Message Text="$(MatlabCommand)" Importance="High" />
<Exec Command="$(MatlabCommand)" ConsoleToMSBuild="true" />

3 Answers 3

1

In Visual Studio, you can config your MSBuild verbosity in Tools –> Options –> Projects and Solutions –> Build and Run.

MSBuild project build output verbosity

From here:

Verbosity set to Quiet – shows either success or the build failure. 1 line displayed below for successful build.

Verbosity set to Minimal – shows the command line for the build. 2 lines displayed for successful rebuild.

Verbosity set to Normal. Shows the output from the MSBuild Targets. 25 lines displayed for successful rebuild.

Verbosity set to Detailed. Much more comments shown from MSBuild. 395 lines displayed for successful build.

And lastly, Verbosity set to Diagnostic, shows you everything. 1097 lines displayed for successful build.

Sign up to request clarification or add additional context in comments.

1 Comment

The question is not about the content of the output window (which this setting affects), its to do with when the output appears. I want the output to appear as it is generated during the build process. It is only appearing at the end, after the build process completes.
1

For this issue, I recommend you use msbuild command like msbuild xxx.csproj by developer command prompt to see the targets being processed.

enter image description here

So am I just missing a setting somewhere?

No, indeed you're right and for now, the output in Visual studio seems to not support for real-time display after my test.

Details to describe this situation:

As we know, there has two ways to build vs project: 1. Build in Visual Studio 2. Msbuild.exe.

Build process in VS(#1) actually calls the Msbuild tool(#2) to work.

Msbuild tool will display the target to a console window in real-time.

And in VS, the output of its build seems like a Non-real-time log, which will display after the build process ends.If we add a Time-consuming operation like yours, it won't display until the command ends. I've done a test for this, create a simple test.csproj, and add a script like this:

 <Target Name="WaitingToDoSth" AfterTargets="Test1">
    <Exec Command="$(ProjectDir)DoSth.exe"/>
  </Target>

This DoSth.exe has a Thread.sleep(3000) in it. In VS, the output won't display anything until the DoSth.exe executes successfully and the entire build process ends. When using msbuild xxx.csproj command in developer command prompt for VS2017, the display can be real-time and we can see messages that occur as the targets are being processed.

If my answer is helpful, please give a feedback. Thank you.

2 Comments

Thanks. You've confirmed what I suspected. However, I'm confused that the SmartExec MSBuild extension task does not resolve this issue as it seems that this is what it is intended for.
Not sure the reason, but the extension has something wrong on my side. It seems doesn't work in my latest vs version(Or maybe I'm using the wrong way). For this , I think you can ask him for this in VSX MarketPlace. And thanks for your feedback.
1

The key to seeing MSBuild output in realtime is to use the MSBuild project SDK. Many thanks to rainersigwald that posted this solution on GitHub:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <RootNamespace>_5451</RootNamespace>
  </PropertyGroup>

  <Target Name="LogStuffInRealTime" BeforeTargets="CoreCompile">
    <Exec Command="ping 127.0.0.1" YieldDuringToolExecution="True" ConsoleToMSBuild="true" StandardOutputImportance="high">
      <Output TaskParameter="ConsoleOutput" ItemName="OutputOfExec" />
    </Exec> 
  </Target>
</Project>

3 Comments

Does this only work for .NET projects? I have a WIX installer project (.wixproj) that contains a number of output harvesting steps that I would like to show realtime output. I also have a C++ project that includes a step that requires compiling items inside Matlab where realtime output would b every useful.
A guy from Microsoft told me that msbuild real-time output "should" work with the older style project files, too. I'll probably open an issue as that does not seem to be the case. I have several different examples here: github.com/gojimmypi/msbuildCustomTask
oh - and be sure to check out this issue I opened: github.com/microsoft/msbuild/issues/5486 "NET.Sdk build runs unexpectedly"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.