Download presentation
Presentation is loading. Please wait.
Published byEser Uçar Modified over 5 years ago
1
Martin Ullrich @dasMulli
MSBuild Martin Ullrich @dasMulli
2
Hi, I’m Martin @dasMulli Martin Ullrich Martin Andreas Ullrich
Senior Consultant at Tieto Austria Software Engineer C#/.NET, iOS (ObjC/Swift), Java, Frontends, … Cares about Build Automation, CI / CD Somewhat active on .NET Core GitHub Repos Learned MSBuild in 2016 @dasMulli Martin Ullrich
4
Agenda Overview and Context How it works Diagnosing Issues
Demos - Tips and Tricks Questions, Questions, Questions
5
Goals Never use „xcopy“ in build events again
Have an easier time navigating .csproj files
6
MSBuild: “The 2003 Format”
7
Project.json 😢 { "version": "1.2.3", "dependencies": {
"Newtonsoft.Json": "10.0.1” }, "frameworks": { "netcoreapp1.0": { "Microsoft.NetCore.App": { "type": "platform", "version": "1.0.0" }
8
The Reality
9
Why didn’t project.json save us all?
.csproj too complicated back then Chicken or the egg problem How do I migrate 100 projects? .NET Standard projects need to be referenced by existing projects. “.xproj” Visual Studio and existing tools are built around MSBuild Limited extensibility
10
Other dotnet CLI issues
Re-implemented many MSBuild features Incremental compilation Configuration management NuGet packages containing MSBuild logic no longer work Missing Features / Edge cases / Bugs Visual Studio: UI over project.json OmniSharp & others: separate handling
11
Build Systems ”flexible” DSL Code Gulp Grunt project.json Gradle
MSBuild Maven Cake
12
New Console App – Classic csproj
13
New Console App – “SDK-style” csproj
14
MSBuild 15 Open Source 🎉 - https://github.com/Microsoft/msbuild
Runs on .NET Core and Mono Replaces xbuild on Mono Syntactic sugar SDKs, Metadata Attributes for Items, … Automatically discovered files Directory.Build.(props|targets|rsp) Performance Improvements More Features & Functionality on each minor release
15
Tooling - IDEs Visual Studio OmniSharp Visual Studio for Mac Rider
Visual Studio Code Atom, Vim, … Visual Studio for Mac Rider 3rd party tools E.g. dotnet-outdated
16
Visual Studio: Project Systems
17
Visual Studio: Project Systems
csproj.dll, msvbproj.dll Native, COM-based Single-threaded, bound to UI Thread “the new project system” – dotnet/project-system Managed Multi-threaded, scalable, responsive Developed on GitHub Some Features may or may not work yet
18
MSBuild 101
19
MSBuild 101 XML Format Definitions + Logic "Variables”, “Lists”
Can look like a DSL "Variables”, “Lists” Conditions, Loops Control Flow Is it a programming language?
20
MSBuild 101: Code Demo
21
Project Files Any XML file can be an MSBuild project
.props / .targets are only a loose convention .props = Beginning of files / contain defaults .targets = End of files / build logic MSBuild command line looks for *.*proj files by default
22
Properties vs. Items Key-Value Pair “Variable” Single Value
Environment Variables are Properties Well-Known Properties Global Properties Can override definition in project file Collections “Lists” Identity + Metadata Duplicates are possible May represent files on disk Glob Patterns Used for Batching “Loops”, “Group By” Item Definition Default Metadata
23
Properties $(MyProperty)
24
Items @(MyItems) MyItemA;MyItemB @(MyItems->’%(Identity).old’)
MyItemA.old;MyItemB.old @(Person->’%(LastName)’, ‘ - ‘) Ullrich – Doe
25
Warning: Static Evaluation
All project XML is scanned before targets run “Static Evaluation” Order is important here: Properties and Imports Item definitions Items Allows for a few ”default item” features EnableDefaultItems EnableDefaultCompileItems …
26
Property Functions MSBuild allows calling .NET code
Built-In functions Some select .NET Types <NewGuid>$([System.Guid]::NewGuid())</NewGuid> <Sum>$([MSBuild]::Add($(CommitCount), 2))</Sum> <IsBeta>$(Version.EndsWith(‘beta’))</IsBeta>
27
Targets Contain actual build logic Only run once Contains tasks
Property and Item Groups are “intrinsic tasks” Targets can have dependencies Graph Targets can define Inputs and Outputs Enables incremental builds (skipping targets) Newest timestamps of Inputs and Outputs are compared
28
Project SDKs Automatic Imports SdkResolvers try to find the SDK
Name or Name/Version On disk or NuGet On disk: .NET Core CLIs with compatible MSBuild versions “Sdk\Sdk.props” and “Sdk\Sdk.targets” will be imported automatically Import tag also supports Sdk attribute
29
Diagnostics?
30
So you just hit a build error…
Logs are your best friend Verbose logs: msbuild -flp:verbosity=diag Binary logs (15.3+): msbuild -bl Embeds project file contents Super helpful for looking at issues without the source Structured Log Viewer
31
Project File Demos
32
More Demos?
33
Demo Menu Publish for multiple target frameworks
Using ”MSBuild Scripts” for your CI pipeline 1 Directory, multiple SDK-style csproj files Include referenced Projects in NuGet package Ship your build logic as NuGet packages + Create your own “Project SDK” Create inline MSBuild Tasks with RolsynCodeTaskFactory Creating a cross-platform MSBuild Task
34
Questions?
35
Useful Links https://github.com/Microsoft/msbuild
MSBuild reserved and well-known properties MSBuild well-known item metadata Common MSBuild project properties Common MSBuild project items Additions to the csproj format for .NET Core
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.