-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
685 lines (559 loc) · 22.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Introduction to MSBuild</title>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="reveal.js/css/reveal.min.css">
<link rel="stylesheet" href="reveal.js/css/theme/default.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="reveal.js/lib/css/zenburn.css">
<!-- If the query includes 'print-pdf', use the PDF print sheet -->
<script>
document.write( '<link rel="stylesheet" href="reveal.js/css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</script>
<!--[if lt IE 9]>
<script src="reveal.js/lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h1>Introduction to MSBuild</h1>
<h3>Artur Dorochowicz</h3>
<p>
<a href="https://github.com/ArturDorochowicz/" target="_blank">
https://github.com/ArturDorochowicz/</a>
</p>
</section>
<section>
<img src="cloud.png" alt="" />
</section>
<section data-transition="linear" data-background="#4d7e65" data-background-transition="slide">
<h2>Agenda</h2>
<ol>
<li>Building blocks</li>
<li>Visual Studio solution</li>
<li>Command line</li>
<li>Debugging</li>
<li>Demos</li>
</ol>
</section>
<section data-transition="linear" data-background="#8c4738" data-background-transition="slide">
<h2>Building blocks</h2>
</section>
<section>
<h2>Project</h2>
<ul>
<li>DefaultTargets - optional, in VS it's usually "Build"</li>
<li>.targets - convention for projects for importing</li>
</ul>
<pre><code data-trim contenteditable>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
DefaultTargets="Foo; Bar"
InitialTargets="Baz">
<Import Project="MyCustom.targets" />
</Project>
</code></pre>
</section>
<section>
<h2>Targets</h2>
<ul>
<li>Targets group tasks together and form the dependency tree</li>
<li><em>Build</em>, <em>Rebuild</em> and <em>Clean</em> are targets</li>
<li>Target is only run once in a given build</li>
</ul>
<pre><code data-trim contenteditable>
<Target Name="MyTarget"
AfterTargets="Foo"
BeforeTargets="Bar"
DependsOnTargets="Baz; Qux">
<CallTargets Targets="Foobar" />
</Target>
</code></pre>
<aside class="notes">
Targets group tasks together in a particular order and allow the build process to be factored into smaller units.
</aside>
</section>
<section>
<h2>Properties</h2>
<ul>
<li>Scalar values</li>
<li>No need to <em>declare</em> before use</em>
<li>Reference with $(property)</li>
</ul>
<pre><code data-trim contenteditable>
<PropertyGroup>
<FirstName>John</FirstName>
<LastName>Doe<LastName>
<FullName>$(FirstName) $(LastName)<FullName>
</PropertyGroup>
</code></pre>
<aside class="notes">
Property names are not case sensitive.
</aside>
</section>
<section>
<h2>Predefined Properties</h2>
<ul>
<li>$(MSBuildProjectDirectory)</li>
<li>$(MSBuildThisFileDirectory)</li>
<li>$(MSBuildLastTaskResult)</li>
<li>$(MSBuildBinPath)</li>
<li>$(MSBuildExtensionsPath)</li>
<li>$(MSBuildToolsPath)</li>
<li>Environment variables are available as properties</li>
</ul>
<p>
<small>
<a href="http://msdn.microsoft.com/en-us/library/vstudio/ms164309.aspx" target="_blank">
http://msdn.microsoft.com/en-us/library/vstudio/ms164309.aspx</a>
</small>
</p>
<aside class="notes">
Reserved properties - cannot be overwritten.
Well-known properties - can be overwritten.
Common VS projects properties: http://msdn.microsoft.com/en-us/library/vstudio/bb629394.aspx
</aside>
</section>
<section>
<h2>Property Functions - .NET</h2>
<p>System.String instance methods</p>
<pre><code data-trim contenteditable>
<PropertyGroup>
<Sample>FooBar</Sample>
<Sub>$(Sample.Substring(0, 3))</Sub>
<Contains>$(Sample.Contains("Bar")</Contains>
</PropertyGroup>
</code></pre>
</section>
<section>
<h2>Property Functions - .NET</h2>
<p>All static methods and properties on selected .NET types</p>
<pre><code data-trim contenteditable>
<PropertyGroup>
<NewGuid>$([System.Guid]::NewGuid())</NewGuid>
<Today>$([System.DateTime]::Now.ToString("yyyy-MM-dd"))</Today>
<Power>$([System.Math]::Pow(2,8))</Power>
<TempFile>$([System.IO.Path]::GetTempFileName())</TempFile>
</PropertyGroup>
</code></pre>
<p>
Selected methods and properties on: System.Environment, System.IO.Directory, System.IO.File
</p>
<p>
<small>
<a href="http://msdn.microsoft.com/en-us/library/dd633440.aspx" target="_blank">
http://msdn.microsoft.com/en-us/library/dd633440.aspx</a>
</small>
</p>
</section>
<section>
<h2>Property Functions - MSBuild</h2>
<pre><code data-trim contenteditable>
<PropertyGroup>
<Value>
$([MSBuild]::MakeRelative(
$(FileOrFolderPath1), $(FileOrFolderPath2)))
$([MSBuild]::GetRegistryValue(
'HKEY_LOCAL_MACHINE\SOFTWARE\(SampleName)', '(SampleValue)'))
$([MSBuild]::Add($(NumberOne), $(NumberTwo)))
$([MSBuild]::BitwiseAnd(
32, $([System.IO.File]::GetAttributes(tempFile))))
</Value>
</PropertyGroup>
</code></pre>
<p>
<small>
<a href="http://msdn.microsoft.com/en-us/library/dd633440.aspx" target="_blank">
http://msdn.microsoft.com/en-us/library/dd633440.aspx</a>
</small>
</p>
</section>
<section>
<h2>Items</h2>
<p>
Lists of values, usually files
</p>
<pre><code data-trim contenteditable>
<ItemGroup>
<File Include="path\to\file.txt" />
<Files Include="path\to\file.txt; path\to\another.txt" />
<FilesWildcard Include="path\to\*.txt" />
<FilesRecursiveWildcard Include="path\**\*.txt" />
<SomeFilesButNotOthers Include="path\to\*.txt"
Exclude="path\to\not-this-one.txt" />
<FilesAdd Include="path\to\fileA.txt" />
<FilesAdd Include="path\to\fileB.txt; fileC.xml"
Exclude="**\*.txt" />
</ItemGroup>
</code></pre>
</section>
<section>
<h2>Well-known item metadata</h2>
<pre><code data-trim contenteditable>
<!-- C:\MyProject\Source\Program.cs -->
<ItemGroup>
<MyItem Include="Source\Program.cs" />
</ItemGroup>
</pre></code>
<ul>
<li>%(FullPath) <em>C:\MyProject\Source\Program.cs</em></li>
<li>%(RootDir) <em>C:\</em></li>
<li>%(Filename) <em>Program</em></li>
<li>%(Extension) <em>.cs</em></li>
<li>%(RelativeDir) <em>Source\</em></li>
<li>%(Directory) <em>MyProject\Source\</em></li>
<li>%(RecursiveDir) here empty; path matched by ** wildcard</li>
<li>%(Identity) <em>Source\Program.cs</em></li>
<li>%(ModifiedTime), %(CreatedTime), %(AccessedTime) <br/>
e.g. <em>2004-08-14 16:52:36.3168743</em></li>
</ul>
<p>
<small>
<a href="http://msdn.microsoft.com/en-us/library/vstudio/ms164313.aspx" target="_blank">
http://msdn.microsoft.com/en-us/library/vstudio/ms164313.aspx</a>
</small>
</p>
</section>
<section>
<h2>Custom item metadata</h2>
<pre><code data-trim contenteditable>
<ItemGroup>
<Reference Include="MyAssembly">
<Private>True</Private>
<HintPath>..\lib\MyAssembly.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
</ItemGroup>
</pre></code>
</section>
<section>
<h2>Custom item metadata</h2>
<h3>Item definition</h3>
<pre><code data-trim contenteditable>
<ItemDefinitionGroup>
<MyItem>
<Custom1>1</Custom1>
<Custom2>2</Custom2>
</MyItem>
</ItemDefinitionGroup>
<ItemGroup>
<MyItem Include="file.txt">
<Custom2>other</Custom2>
<Custom3>3</Custom3>
</MyItem>
</ItemGroup>
</pre></code>
</section>
<section>
<h2>Tasks</h2>
<pre><code data-trim contenteditable>
<ItemGroup>
<MySourceFiles Include="c:\MySourceTree\**\*.*" />
</ItemGroup>
<Target Name="CopyFiles">
<Copy
SourceFiles="@(MySourceFiles)"
DestinationFiles="@(MySourceFiles->
'c:\MyDestinationTree\%(RecursiveDir)%(Filename)%(Extension)')"
/>
</Target>
</pre></code>
<aside class="notes">
Tasks may only be used within targets.
</aside>
</section>
<section>
<h2>Built-in tasks</h2>
<table>
<tbody>
<tr>
<td>AspNetCompiler</td>
<td>CallTarget</td>
<td>Copy</td>
<td>CombinePath</td>
</tr>
<tr>
<td>Delete</td>
<td>Error</td>
<td>Exec</td>
<td>MakeDir</td>
</tr>
<tr>
<td>Message</td>
<td>Move</td>
<td>MSBuild</td>
<td>ReadLinesFromFile</td>
</tr>
<tr>
<td>RemoveDir</td>
<td>Touch</td>
<td>Warning</td>
<td>WriteLinesToFile</td>
</tr>
<tr>
<td>XmlPeek</td>
<td>XmlPoke</td>
<td>XslTransformation</td>
</tr>
</tbody>
</table>
<p>
<small>
<a href="http://msdn.microsoft.com/en-us/library/7z253716(v=vs.100).aspx" target="_blank">
http://msdn.microsoft.com/en-us/library/7z253716(v=vs.100).aspx</a>
</small>
</p>
</section>
<section>
<h2>External tasks</h2>
<pre><code data-trim contenteditable>
<UsingTask
TaskName="Microsoft.TeamFoundation.Build.Tasks.GetBuildProperties"
AssemblyFile="$(TeamBuildRefPath)\Microsoft.TeamFoundation.Build.ProcessComponents.dll"
/>
<Target Name="MyTarget">
<GetBuildProperties
TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
BuildUri="$(BuildUri)">
<Output TaskParameter="BuildNumber"
PropertyName="BuildNumber" />
<Output TaskParameter="SourceGetVersion"
PropertyName="SourceGetVersion" />
</GetBuildProperties>
</Target>
</pre></code>
</section>
<section>
<h2>Popular task collections</h2>
<ul>
<li>
MSBuild Extension Pack<br/>
<small>
<a href="https://msbuildextensionpack.codeplex.com/" target="_blank">
https://msbuildextensionpack.codeplex.com/</a><br/>
<a href="https://www.nuget.org/packages/MSBuild.Extension.Pack/" target="_blank">
https://www.nuget.org/packages/MSBuild.Extension.Pack/</a>
</small>
</li>
<li>
MSBuild Community Tasks<br/>
<small>
<a href="https://github.com/loresoft/msbuildtasks/" target="_blank">
https://github.com/loresoft/msbuildtasks/</a><br/>
<a href="https://www.nuget.org/packages/MSBuildTasks" target="_blank">
https://www.nuget.org/packages/MSBuildTasks</a>
</small>
</li>
</ul>
</section>
<section>
<section>
<h2>Inline tasks</h2>
<aside class="notes">
Parameter type is optional and defaults to string.
Full type name must be used (e.g. System.Boolean).
</aside>
</section>
<section>
<pre><code data-trim contenteditable>
<UsingTask TaskName="FilterList" TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<ListToFilter ParameterType="Microsoft.Build.Framework.ITaskItem[]"
Required="true" />
<Filter Required="true" />
<FilteredList ParameterType="Microsoft.Build.Framework.ITaskItem[]"
Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.Text.RegularExpressions" />
<Code Type="Fragment" Language="cs">
<![CDATA[
var results = ListToFilter
.Where(x => Regex.IsMatch(x.ItemSpec, Filter));
FilteredList = results.ToArray();
]]>
</Code>
</Task>
</UsingTask>
</pre></code>
</section>
<section>
<pre><code data-trim contenteditable>
<ItemGroup>
<Source Include="file.txt; file.cs" />
</ItemGroup>
<Target Name="MyTarget">
<FilterList ListToFilter="@(Source)" Filter="\.cs$">
<Output ItemName="_FilteredList" TaskParameter="FilteredList" />
</FilterList>
</Target>
</pre></code>
</section>
</section>
<section>
<h2>Conditions</h2>
<pre><code data-trim contenteditable>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<MvcBuildViews>true</MvcBuildViews>
</PropertyGroup>
<PropertyGroup>
<OutDir Condition="'$(OutDir)' == ''">
$(MSBuildProjectDirectory)\bin</OutDir>
</PropertyGroup>
</pre></code>
<p>Operators</p>
<ul>
<li>== != <em>strings</em></li>
<li>> < >= <= <em>numbers</em></li>
<li>Exists() HasTrailingSlash() <em>strings</em></li>
<li>! And Or</li>
</ul>
</section>
<section data-transition="linear" data-background="#8c4738" data-background-transition="slide">
<h2>Visual Studio solutions</h2>
</section>
<section>
<h2>MSBuild vs SLN</h2>
<ul>
<li><em>.sln</em> - not an MSBuild XML project file</li>
<li>Converted to a project on the fly</li>
<li><em>set MSBUILDEMITSOLUTION=1</em> - saves generated project to file</li>
</ul>
</section>
<section>
<h2>.sln extensibility</h2>
<pre><code data-trim contenteditable>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" InitialTargets="ValidateSolutionConfiguration;ValidateToolsVersions;ValidateProjects">
<Import
Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\SolutionFile\ImportBefore\*"
Condition="'$(ImportByWildcardBeforeSolution)' != 'false' and exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\SolutionFile\ImportBefore')" />
<Import
Project="$(MSBuildProjectDirectory)\before.MySln.sln.targets"
Condition="exists('before.MySln.sln.targets')" />
<!-- Properties/Items/Targets here -->
<Import
Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\SolutionFile\ImportAfter\*"
Condition="'$(ImportByWildcardBeforeSolution)' != 'false' and exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\SolutionFile\ImportAfter')" />
<Import
Project="$(MSBuildProjectDirectory)\after.MySln.sln.targets"
Condition="exists('after.MySln.sln.targets')" />
</Project>
</code></pre>
<aside class="notes">
http://sedodream.com/2010/10/22/MSBuildExtendingTheSolutionBuild.aspx
</aside>
</section>
<section data-transition="linear" data-background="#8c4738" data-background-transition="slide">
<h2>Command line</h2>
</section>
<section>
<h2>Command line</h2>
<pre><code data-trim contenteditable>
msbuild.exe MySolution.sln
/target:Rebuild
/property:Configuration=Release /property:DeployOnBuild=True
/verbosity:diagnostic
/maxcpucount
/nodereuse:false
</code></pre>
<p>
Properties set on the command line become constants
</p>
<p>
<small>
<a href="http://msdn.microsoft.com/en-us/library/vstudio/ms164311(v=vs.100).aspx" target="_blank">
http://msdn.microsoft.com/en-us/library/vstudio/ms164311(v=vs.100).aspx</a>
</small>
</p>
<aside class="notes">
Properties set from command line are constants.
Percent encoding.
<ul>
<li>c:\Windows\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe</li>
<li>c:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe</li>
<li>c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</li>
<li>c:\Windows\Microsoft.NET\Framework64\v2.0.50727\MSBuild.exe</li>
<li>c:\Windows\Microsoft.NET\Framework64\v3.5\MSBuild.exe</li>
<li>c:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe</li>
</ul>
</aside>
</section>
<section data-transition="linear" data-background="#8c4738" data-background-transition="slide">
<h2>Debugging</h2>
</section>
<section>
<h2>Debugging</h2>
<pre><code data-trim contenteditable>
C:\Windows\system32\reg add
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\4.0"
/v DebuggerEnabled /d true
C:\Windows\SysWOW64\reg add
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\4.0"
/v DebuggerEnabled /d true
</code></pre>
<p>
and <br/>
Turn on <em> Enable Just My Code</em> in VS Options/Debugging/General
</p>
<p>
Then
</p>
<pre><code data-trim contenteditable>
msbuild.exe ... /debug
</code></pre>
<p>or</p>
<pre><code data-trim contenteditable>
SET MSBUILDDEBUGGING=1
</code></pre>
<aside class="notes">
http://blogs.msdn.com/b/visualstudio/archive/2010/07/06/debugging-msbuild-script-with-visual-studio.aspx
http://blogs.msdn.com/b/visualstudio/archive/2010/07/09/debugging-msbuild-script-with-visual-studio-2.aspx
http://blogs.msdn.com/b/visualstudio/archive/2010/07/09/debugging-msbuild-script-with-visual-studio-3.aspx
</aside>
</section>
<section data-transition="linear" data-background="#8c4738" data-background-transition="slide">
<h2>Demos</h2>
</section>
<section>
<h1>Introduction to MSBuild</h1>
<h3>Artur Dorochowicz</h3>
<p>
<a href="https://github.com/ArturDorochowicz/presentation-introduction-to-msbuild" target="_blank">
https://github.com/ArturDorochowicz/presentation-introduction-to-msbuild</a>
</p>
</section>
</div>
</div>
<script src="reveal.js/lib/js/head.min.js"></script>
<script src="reveal.js/js/reveal.min.js"></script>
<script>
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/fade/none
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'reveal.js/plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal.js/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal.js/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'reveal.js/plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'reveal.js/plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>