TExcelTAD
Home › .NET Builds: MSBuild & NuGet › Toolkit: IDEs & the Structured Log Viewer

Toolkit: IDEs & the Structured Log Viewer

The dotnet CLI is the reference: every IDE runs the same MSBuild and NuGet underneath, so a build that works on the command line works everywhere. The tools in this lesson make the same information easier to see. Most are graphical and can't run in this course's sandbox; where a command-line equivalent exists, it's shown for real.

IDEs and how they build

Tool Build engine Worth knowing
Visual Studio (Windows) MSBuild in-process, design-time builds for IntelliSense Tools → Options → Projects and Solutions → Build and Run sets the log verbosity of the Output window; the Project System Tools extension records binlogs of design-time builds, which is how you debug "IntelliSense says X, the build says Y"
JetBrains Rider (all platforms) the dotnet SDK's MSBuild the Build tool window has a structured view of targets; Rider can open .binlog files directly
VS Code + C# Dev Kit the SDK, via a language server the Solution Explorer reads .sln/.slnx; build tasks call dotnet build, so CLI flags and Directory.Build.props apply unchanged

Two consequences for build engineers:

  • IDEs run design-time builds (a subset of targets, such as ResolveReferences and CoreCompile in "skip" mode) every time a project file changes. Expensive custom targets should skip them: Condition="'$(DesignTimeBuild)' != 'true'".
  • Settings that only exist in an IDE (a Visual Studio "build configuration" ticked off for one project, a Rider run configuration) don't exist in CI. Keep anything the build needs in project files.

dotnet format: the formatter in the SDK

Code style is part of the build too: dotnet format applies .editorconfig rules and analyzer fixes, and --verify-no-changes turns it into a CI check.

bash · try it yourself
mkdir fmt && cd fmt
cat > fmt.csproj <<'XML'
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
  </PropertyGroup>
</Project>
XML
printf 'public class   Area{\npublic int Of(int w,int h){return w*h;}\n}\n' > Area.cs
dotnet format whitespace --verify-no-changes 2>&1 | sed 's|/home/learner/fmt/||g'
echo "exit code: ${PIPESTATUS[0]}"
dotnet format whitespace
cat Area.cs
dotnet format whitespace --verify-no-changes && echo "clean"
Area.cs(1,14): error WHITESPACE: Fix whitespace formatting. Delete 2 characters. [fmt.csproj]
Area.cs(1,20): error WHITESPACE: Fix whitespace formatting. Insert '\n'. [fmt.csproj]
Area.cs(2,1): error WHITESPACE: Fix whitespace formatting. Insert '\s\s\s\s'. [fmt.csproj]
Area.cs(2,21): error WHITESPACE: Fix whitespace formatting. Insert '\s'. [fmt.csproj]
Area.cs(2,27): error WHITESPACE: Fix whitespace formatting. Insert '\s'. [fmt.csproj]
Area.cs(2,28): error WHITESPACE: Fix whitespace formatting. Insert '\s'. [fmt.csproj]
Area.cs(2,36): error WHITESPACE: Fix whitespace formatting. Insert '\s'. [fmt.csproj]
Area.cs(2,37): error WHITESPACE: Fix whitespace formatting. Insert '\s'. [fmt.csproj]
Area.cs(2,39): error WHITESPACE: Fix whitespace formatting. Insert '\s'. [fmt.csproj]
exit code: 2
public class Area
{
    public int Of(int w, int h) { return w * h; }
}
clean

dotnet format has three sub-commands: whitespace (layout only, no build needed), style (code-style rules from .editorconfig) and analyzers (third-party analyzer fixes). Plain dotnet format runs all three. The non-zero exit code is what fails a CI job.

The MSBuild Structured Log Viewer

The single most useful tool for build problems, by Kirill Osenkov, free and open source: a desktop app for Windows, macOS and Linux (installers at msbuildlog.com), plus a browser version at live.msbuildlog.com that opens a .binlog locally without uploading it. Record a log with -bl, then open it. Not run here (it's a GUI); this is what you'll use it for:

  • Search across everything: $property OutputPath, $target CoreCompile, $task Exec, item names, file paths, text in messages. The results show where each value was set.
  • Why did this target run? Each target node shows whether it ran or was skipped and why ("Skipping target because all output files are up-to-date" or "Input file X is newer than output file Y").
  • Timeline and tracing views: which projects built in parallel, which targets were on the critical path, how long each task took. The "Target summary" pane sorts targets by total time.
  • Evaluation profiling: with -profileEvaluation:eval.md on the command line (or in the viewer) you see the cost of each import and glob, which finds the **/* glob that scans node_modules.
  • Embedded files: every project, props and targets file the build read, exactly as it was, so you can debug a CI build without its machine.

The underlying data is the same one-pass event stream the console logger sees. The viewer's "target summary" is just aggregation over it, which is easy to model:

python · try it yourself
# (project, target, start_ms, end_ms, parent target or None)
events = [
    ("App", "Build", 0, 2400, None),
    ("App", "ResolveProjectReferences", 10, 1300, "Build"),
    ("Lib", "Build", 20, 1280, "ResolveProjectReferences"),
    ("Lib", "CoreCompile", 100, 1150, "Build"),
    ("App", "ResolvePackageAssets", 1310, 1360, "Build"),
    ("App", "CoreCompile", 1370, 2250, "Build"),
    ("App", "CopyFilesToOutputDirectory", 2260, 2390, "Build"),
]
total = {}
child_time = {}
for proj, tgt, start, end, parent in events:
    total[(proj, tgt)] = end - start
for proj, tgt, start, end, parent in events:
    if parent:
        # a parent in the same project, or the referencing project's target
        owner = next(p for p, t, *_ in events if t == parent and (p == proj or parent == "ResolveProjectReferences"))
        child_time[(owner, parent)] = child_time.get((owner, parent), 0) + end - start
print(f"{'target':36} {'inclusive':>9} {'exclusive':>9}")
for key in sorted(total, key=lambda k: -(total[k] - child_time.get(k, 0))):
    excl = total[key] - child_time.get(key, 0)
    print(f"{key[0] + '/' + key[1]:36} {total[key]:>7}ms {excl:>7}ms")
target                               inclusive exclusive
Lib/CoreCompile                         1050ms    1050ms
App/CoreCompile                          880ms     880ms
Lib/Build                               1260ms     210ms
App/CopyFilesToOutputDirectory           130ms     130ms
App/Build                               2400ms      50ms
App/ResolvePackageAssets                  50ms      50ms
App/ResolveProjectReferences            1290ms      30ms

Inclusive time includes everything a target waited for; exclusive time is its own work. App/Build looks slow inclusively but does almost nothing itself; the compiler targets are where the time goes. The viewer shows both columns for every target and task.

Other helpers

  • dotnet build-server shutdown stops the compiler server (VBCSCompiler) and MSBuild node processes that stay alive between builds for speed. Use it when a build seems to use stale state or holds file locks.
  • dotnet watch rebuilds and reruns (with hot reload where possible) on file changes; it uses MSBuild to know which files to watch.
  • global.json (dotnet new globaljson) pins the SDK version a repository builds with; rollForward controls how strict that is. Commit one so CI and developers use the same SDK.

Test yourself

Which flag makes dotnet format suitable as a CI check?

  1. --diagnostics
  2. --verify-no-changes, which reports violations and exits non-zero without changing files
  3. --no-restore
  4. -v:diag

In the Structured Log Viewer, a target's exclusive time is small but its inclusive time is large. What does that mean?

  1. The target is slow
  2. Most of the time was spent in targets it waited on (dependencies or referenced projects), not in its own tasks
  3. The log is corrupt
  4. It ran twice

Why should an expensive custom target check '$(DesignTimeBuild)' != 'true'?

  1. Design-time builds run on CI only
  2. IDEs run design-time builds frequently for IntelliSense; skipping the target keeps the editor responsive
  3. It's required by NuGet
  4. Otherwise the target runs in Release only