This repository has been archived by the owner on Jul 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.msbuild
850 lines (770 loc) · 46.1 KB
/
entrypoint.msbuild
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
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
<?xml version="1.0" encoding="utf-8"?>
<Project
DefaultTargets="Help"
ToolsVersion="14.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Directories -->
<!--
The workspace directory is defined as the directory that is the top-level directory in which all the
files for the build, test, deploy stage can be found. During the process there should never be a need
to go any futher up the directory hierarchy to find files.
Note: Do NOT include a trailing backslash in this property
-->
<DirWorkspace Condition=" '$(DirWorkspace)' == '' ">$(MSBuildProjectDirectory)</DirWorkspace>
<!--
The default directory that the NuGet packages are expanded into
-->
<DirDefaultPackages>$(DirWorkspace)\packages</DirDefaultPackages>
<!--
The directory in which the configuration files, like settings.props, are located.
-->
<DirUserSettings Condition=" '$(DirUserSettings)' == '' ">$(DirWorkspace)</DirUserSettings>
<!-- Files -->
<!--
The location of the 'settings.props' file which describes the shared configuration settings for the
build/test/deploy phases. The other configurations files (e.g. build.settings.props etc.) are expected to
be located in the same directory.
-->
<SharedPropertyFile>$(DirUserSettings)\ops.props</SharedPropertyFile>
<!--
The file that contains all the NuGet packages that are used by the non-compilation parts
of the build and deploy process. NuGet package files that are used by the compilation parts
of the build process are expected to be handled by the compilation process.
-->
<NuGetPackageFile Condition=" '$(NuGetPackageFile)' == '' ">$(DirWorkspace)\packages.config</NuGetPackageFile>
<!--
The file that contains all the NuGet configuration settings for the current project. This file
is used to determine where the package directory is located if no such directory is defined.
-->
<FileNugetConfig Condition=" '$(FileNugetConfig)' == '' ">$(DirWorkspace)\nuget.config</FileNugetConfig>
<!-- Required packages -->
<!--
The name of the package that contains the entry point for the current build.
-->
<PackageNameEntryPoint Condition=" '$(PackageNameEntryPoint)' == '' ">Ops.Tools.Build.EntryPoint</PackageNameEntryPoint>
<!-- External tools -->
<!--
The full path to the NuGet command line application. Expected to be found via the PATH environment variable.
-->
<ToolsExternalNuGetPath Condition=" '$(ToolsExternalNuGetPath)' == '' ">NuGet.exe</ToolsExternalNuGetPath>
<!-- MsBuild -->
<!--
For MsBuild versions 4.0 through to 12.0 the tasks dll was in an assembly that contains the version in the file name.
However starting with version 14 that is no longer the case so have to differentiate between these cases.
-->
<MsBuildTasksAssembly>$(MSBuildToolsPath)\Microsoft.Build.Tasks.v$(MSBuildToolsVersion).dll</MsBuildTasksAssembly>
<MsBuildTasksAssembly Condition="!Exists('$(MsBuildTasksAssembly)')">$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll</MsBuildTasksAssembly>
</PropertyGroup>
<!--
Import the environment specific settings. These settings may be different for different environments, e.g. there might be a difference
between a dev machine and a build machine, so the loading of these files is done slightly differently than other settings files.
We check the following locations in order:
* A user specified location as indicated by the variable: $(FileEnvironment)
* An user environment variable named NBUILDKIT_USER_ENVIRONMENT_FILE
* A machine environment variable named NBUILDKIT_MACHINE_ENVIRONMENT_FILE
* The the workspace
* The default environment settings file provided by nBuildkit
The user can override the location where the file should be loaded from by specifying the 'UseEnvironmentFrom' property and setting it to
one of the following values:
* File - Load the environment information from the user specified file, if it exists
* User - Load the environment information from file pointed to by the user environment variable
NBUILDKIT_USER_ENVIRONMENT_FILE, if it exists
* Machine - Load the environment information from file pointed to by the machine environment variable
NBUILDKIT_MACHINE_ENVIRONMENT_FILE, if it exists
* Workspace - Load the environment information from the file in the workspace, if it exists
-->
<Import
Condition="Exists('$(FileEnvironment)') AND (('$(UseEnvironmentFrom)' == 'File') OR (('$(UseEnvironmentFrom)' == '') AND ('$(ExistsEnvironmentSettings)' != 'true'))) "
Project="$(FileEnvironment)" />
<Import
Condition="Exists('$(NBUILDKIT_USER_ENVIRONMENT_FILE)') AND (('$(UseEnvironmentFrom)' == 'User') OR (('$(UseEnvironmentFrom)' == '') AND ('$(ExistsEnvironmentSettings)' != 'true'))) "
Project="$(NBUILDKIT_USER_ENVIRONMENT_FILE)" />
<Import
Condition="Exists('$(NBUILDKIT_MACHINE_ENVIRONMENT_FILE)') AND (('$(UseEnvironmentFrom)' == 'Machine') OR (('$(UseEnvironmentFrom)' == '') AND ('$(ExistsEnvironmentSettings)' != 'true'))) "
Project="$(NBUILDKIT_MACHINE_ENVIRONMENT_FILE)" />
<Import
Condition="Exists('$(DirUserSettings)\environment.props') AND (('$(UseEnvironmentFrom)' == 'Workspace') OR (('$(UseEnvironmentFrom)' == '') AND ('$(ExistsEnvironmentSettings)' != 'true'))) "
Project="$(DirUserSettings)\environment.props" />
<!--
Display the help text for the current script and then exit.
-->
<Target Name="Help">
<Message Text="Ops.Tools.Build" />
<Message Text="Copyright 2016 Ops-Resource." />
<Message Text="" />
<Message Text="The following targets exist:" />
<Message Text="" />
<Message Text="- Build: Executes the build sequence. Build steps are as defined by the 'BuildStepsToExecute' in the 'build.settings.props' file." />
<Message Text=" Additional properties that can be specified are:" />
<Message Text=" * DirWorkspace - The full path to the directory that is the top-level directory in which all the files for the" />
<Message Text=" build, test, deploy stage can be found. During the process there should never be a need to go" />
<Message Text=" any futher up the directory hierarchy to find files." />
<Message Text=" * DirUserSettings - The full path to the directory in which the configuration files, like settings.props, are located." />
<Message Text=" * DirBuildServerSettings - The full path to the directory in which the build server specific configuration files are located." />
<Message Text=" * GroupsToExecute - A comma separated list of groups for which the build steps should be executed." />
<Message Text=" Available groups are Clean and the groups defined in the BuildStepsToExecute list." />
<Message Text=" * FileEnvironment - The full path to an MsBuild properties file that contains the environment settings for the current environment." />
<Message Text=" This file should at least contain a property called 'ExistsEnvironmentSettings' for which the value should be set to true." />
<Message Text=" * UseEnvironmentFrom - A property that indicates where the environment.props file should be loaded from." />
<Message Text=" Valid options are:" />
<Message Text=" - 'File' - Load the environment information from the user specified file, if it exists." />
<Message Text=" - 'User' - Load the environment information from file pointed to by the user environment variable" />
<Message Text=" NBUILDKIT_USER_ENVIRONMENT_FILE, if it exists" />
<Message Text=" - 'Machine' - Load the environment information from file pointed to by the machine environment variable" />
<Message Text=" NBUILDKIT_MACHINE_ENVIRONMENT_FILE, if it exists" />
<Message Text=" - 'Workspace' - Load the environment information from the file in the workspace, if it exists" />
<Message Text="- Test: Executes the test sequence. Test steps are defined by the 'TestStepsToExecute' in the 'test.settings.props' file." />
<Message Text=" Additional properties that can be specified are:" />
<Message Text=" * DirWorkspace - The full path to the directory that is the top-level directory in which all the files for the" />
<Message Text=" build, test, deploy stage can be found. During the process there should never be a need to go" />
<Message Text=" any futher up the directory hierarchy to find files." />
<Message Text=" * DirUserSettings - The full path to the directory in which the configuration files, like settings.props, are located." />
<Message Text=" * DirBuildServerSettings - The full path to the directory in which the build server specific configuration files are located." />
<Message Text=" * GroupsToExecute - A comma separated list of groups for which the build steps should be executed." />
<Message Text=" Available groups are Clean and the groups defined in the TestStepsToExecute list." />
<Message Text=" * FileEnvironment - The full path to an MsBuild properties file that contains the environment settings for the current environment." />
<Message Text=" This file should at least contain a property called 'ExistsEnvironmentSettings' for which the value should be set to true." />
<Message Text=" * UseEnvironmentFrom - A property that indicates where the environment.props file should be loaded from." />
<Message Text=" Valid options are:" />
<Message Text=" - 'File' - Load the environment information from the user specified file, if it exists." />
<Message Text=" - 'User' - Load the environment information from file pointed to by the user environment variable" />
<Message Text=" NBUILDKIT_USER_ENVIRONMENT_FILE, if it exists" />
<Message Text=" - 'Machine' - Load the environment information from file pointed to by the machine environment variable" />
<Message Text=" NBUILDKIT_MACHINE_ENVIRONMENT_FILE, if it exists" />
<Message Text=" - 'Workspace' - Load the environment information from the file in the workspace, if it exists" />
<Message Text="- Deploy: Executes the deploy sequence. Deploy steps are as defined by the 'DeployStepsToExecute' in the 'deploy.settings.props' file." />
<Message Text=" Additional properties that can be specified are:" />
<Message Text=" * DirWorkspace - The full path to the directory that is the top-level directory in which all the files for the" />
<Message Text=" build, test, deploy stage can be found. During the process there should never be a need to go" />
<Message Text=" any futher up the directory hierarchy to find files." />
<Message Text=" * DirUserSettings - The full path to the directory in which the configuration files, like settings.props, are located." />
<Message Text=" * DirBuildServerSettings - The full path to the directory in which the build server specific configuration files are located." />
<Message Text=" * GroupsToExecute - A comma separated list of groups for which the build steps should be executed." />
<Message Text=" Available groups are Clean and the groups defined in the DeployStepsToExecute list." />
<Message Text=" * FileEnvironment - The full path to an MsBuild properties file that contains the environment settings for the current environment." />
<Message Text=" This file should at least contain a property called 'ExistsEnvironmentSettings' for which the value should be set to true." />
<Message Text=" * UseEnvironmentFrom - A property that indicates where the environment.props file should be loaded from." />
<Message Text=" Valid options are:" />
<Message Text=" - 'File' - Load the environment information from the user specified file, if it exists." />
<Message Text=" - 'User' - Load the environment information from file pointed to by the user environment variable" />
<Message Text=" NBUILDKIT_USER_ENVIRONMENT_FILE, if it exists" />
<Message Text=" - 'Machine' - Load the environment information from file pointed to by the machine environment variable" />
<Message Text=" NBUILDKIT_MACHINE_ENVIRONMENT_FILE, if it exists" />
<Message Text=" - 'Workspace' - Load the environment information from the file in the workspace, if it exists" />
<Message Text="" />
<Message Text="Additionally the following environment variables may be defined:" />
<Message Text="- NBUILDKIT_USER_ENVIRONMENT_FILE - A user level environment variable that defines the full path to an MsBuild properties file that contains the environment settings." />
<Message Text=" This file should at least contain a property called 'ExistsEnvironmentSettings' for which the value should be set to true." />
<Message Text="- NBUILDKIT_MACHINE_ENVIRONMENT_FILE - A machine level environment variable that defines the full path to an MsBuild properties file that contains the environment settings." />
<Message Text=" This file should at least contain a property called 'ExistsEnvironmentSettings' for which the value should be set to true." />
<Message Text="- NBUILDKIT_BUILDSERVER_ENVIRONMENT_DIR - A user or machine level environment variable that defines the directory path to an MsBuild properties file that contains the" />
<Message Text=" environment settings for the build server." />
<Message Text=" This file should at least contain two properties: One property called 'ExistsBuildServerEnvironmentSettings' for which the" />
<Message Text=" value should be set to true, and a property called 'VersionBuildServerEnvironmentSettings' for which the value should be set to ." />
<Message Text=" value should be set to the version of the settings file." />
<Message Text="- Help: Displays this text." />
</Target>
<!--
Invoke the build steps as defined by the 'settings.props' file by invoking the nBuildKit 'build.msbuild'
script and passing the path to the 'settings.props' file and the version of nBuildKit that is going to
be used to execute the build.
-->
<Target
DependsOnTargets="_EntryPoint_SetTargets_Build;_EntryPoint_Execute"
Name="Build">
</Target>
<Target Name="_EntryPoint_SetTargets_Build">
<PropertyGroup>
<TargetToExecute>Build</TargetToExecute>
</PropertyGroup>
</Target>
<!--
Invoke the test steps as defined by the 'settings.props' file by invoking the nBuildKit 'test.msbuild'
script and passing the path to the 'settings.props' file and the version of nBuildKit that is going to
be used to execute the tests.
-->
<Target
DependsOnTargets="_EntryPoint_SetTargets_Test;_EntryPoint_Execute"
Name="Test">
</Target>
<Target Name="_EntryPoint_SetTargets_Test">
<PropertyGroup>
<TargetToExecute>Test</TargetToExecute>
</PropertyGroup>
</Target>
<!--
Invoke the deploy steps as defined by the 'settings.props' file by invoking the nBuildKit 'deploy.msbuild'
script and passing the path to the 'settings.props' file and the version of nBuildKit that is going to
be used to execute the deploy.
-->
<Target
DependsOnTargets="_EntryPoint_SetTargets_Deploy;_EntryPoint_Execute"
Name="Deploy">
</Target>
<Target Name="_EntryPoint_SetTargets_Deploy">
<PropertyGroup>
<TargetToExecute>Deploy</TargetToExecute>
</PropertyGroup>
</Target>
<Target
DependsOnTargets="_EntryPoint_LocateEntryPoint"
Name="_EntryPoint_Execute">
<Error
Condition=" '$(DirEntryPointPackage)' == '' OR !Exists('$(DirEntryPointPackage)')"
Text="Could not determine the location of the $(PackageNameEntryPoint) NuGet package. The file was expected to be in '$(DirPackages)\$(PackageNameEntryPoint).<VERSION>' directory, but that directory does not exist. Cannot start build." />
<MSBuild
BuildInParallel="False"
Projects="$(DirEntryPointPackage)\run.msbuild"
Properties="DirWorkspace=$(DirWorkspace);DirUserSettings=$(DirUserSettings);DirPackages=$(DirPackages)"
RebaseOutputs="False"
RemoveProperties=""
RunEachTargetSeparately="True"
SkipNonexistentProjects="False"
StopOnFirstFailure="True"
TargetAndPropertyListSeparators=""
Targets="$(TargetToExecute)"
ToolsVersion="$(MSBuildToolsVersion)"
UnloadProjectsOnCompletion="True"
UseResultsCache="True">
</MSBuild>
</Target>
<!--
Get the full path to the entrypoint package directory so that we can invoked the build scripts from there.
-->
<Target
DependsOnTargets="_EntryPoint_LocatePackagesDir;_EntryPoint_RestoreGlobalNugetPackages;_EntryPoint_LocateEntryPointViaPackagesConfig;_EntryPoint_LocatePackageViaHighestAvailableVersion"
Name="_EntryPoint_LocateEntryPoint">
<Message Text="DirEntryPointPackage after search: $(DirEntryPointPackage)" />
<Error
Condition="!Exists('$(DirEntryPointPackage)')"
Text="Unable to find the nBuildKit directory." />
</Target>
<!--
Restore all the packages that are used by the non-compilation part of the build and deploy process. This is required
so that we can be sure that the nBuildKit main package is extacted to the package directory.
-->
<Target
DependsOnTargets="_EntryPoint_LocatePackagesDir"
Name="_EntryPoint_RestoreGlobalNugetPackages">
<EntryPoint_LocalTask_NuGetRestore
Condition="Exists('$(NuGetPackageFile)')"
NuGetPath="$(ToolsExternalNuGetPath)"
PackageDirectory="$(DirPackages)"
PackageFile="$(NuGetPackageFile)"
Sources="@(NuGetSources)" />
</Target>
<Target
Condition="Exists('$(DirPackages)')"
Name="_EntryPoint_LocateEntryPointViaPackagesConfig">
<!-- Get the version of nBuildKit that is expected from the global packages file -->
<XmlPeek
Condition="Exists('$(NuGetPackageFile)')"
Query="//package[@id='$(PackageNameEntryPoint)']/@version"
XmlInputPath="$(NuGetPackageFile)">
<Output
ItemName="VersionEntrypointPackage"
TaskParameter="Result" />
</XmlPeek>
<Message Text="Version: @(VersionEntrypointPackage)" />
<CreateProperty
Condition=" '@(VersionEntrypointPackage)' != '' "
Value="%(VersionEntrypointPackage.Identity)">
<Output
PropertyName="PackageVersion"
TaskParameter="Value" />
</CreateProperty>
<!--
If the packages directory exists then we assume that nBuildKit is in there. If that is not the case we'll get a
non-existing path but that will lead to an error.
-->
<CreateProperty
Condition="Exists('$(DirPackages)') AND Exists('$(DirPackages)\$(PackageNameEntryPoint).$(PackageVersion)\build')"
Value="$(DirPackages)\$(PackageNameEntryPoint).$(PackageVersion)\build">
<Output
PropertyName="DirEntryPointPackage"
TaskParameter="Value" />
</CreateProperty>
<CreateProperty
Condition="Exists('$(DirPackages)') AND Exists('$(DirPackages)\$(PackageNameEntryPoint)\build')"
Value="$(DirPackages)\$(PackageNameEntryPoint)\build">
<Output
PropertyName="DirEntryPointPackage"
TaskParameter="Value" />
</CreateProperty>
<Message Text="DirEntryPointPackage after searching packages.config: $(DirEntryPointPackage)" />
</Target>
<Target
Condition="!Exists('$(DirEntryPointPackage)')"
Name="_EntryPoint_LocatePackageViaHighestAvailableVersion">
<ItemGroup>
<NuGetSourcesToSearch
Condition=" '$(AllowTestVersions)' != 'true' "
Include="$(UriNuGetProductionRead)" />
<NuGetSourcesToSearch
Condition=" '$(AllowTestVersions)' == 'true' AND '@(NuGetSources)' != '' "
Include="@(NuGetSources)" />
</ItemGroup>
<EntryPoint_LocalTask_GetHighestSuitablePackageVersionFromNuGet
NuGetPath="$(ToolsExternalNuGetPath)"
PackageName="$(PackageNameEntryPoint)"
Sources="@(NuGetSourcesToSearch)" >
<Output
PropertyName="PackageVersion"
TaskParameter="Version" />
</EntryPoint_LocalTask_GetHighestSuitablePackageVersionFromNuGet>
<EntryPoint_LocalTask_InstallPackageFromNuGet
NuGetPath="$(ToolsExternalNuGetPath)"
PackageDirectory="$(DirPackages)"
PackageName="$(PackageNameEntryPoint)"
PackageVersion="$(PackageVersion)"
Sources="@(NuGetSourcesToSearch)" />
<CreateProperty
Condition="Exists('$(DirPackages)')"
Value="$(DirPackages)\$(PackageNameEntryPoint)\build">
<Output
PropertyName="DirEntryPointPackage"
TaskParameter="Value" />
</CreateProperty>
<Message Text="DirEntryPointPackage after getting highest allowed version: $(DirEntryPointPackage)" />
</Target>
<!--
Get the full path to the packages directory.
-->
<Target Name="_EntryPoint_LocatePackagesDir">
<!-- Determine if a packages folder exists at the same level as this script. If so use that -->
<CreateProperty
Condition="Exists('$(DirDefaultPackages)')"
Value="$(DirDefaultPackages)">
<Output
PropertyName="DirPackages"
TaskParameter="Value" />
</CreateProperty>
<!-- Get the location of the packages directory from the local nuget.config file -->
<XmlPeek
Condition="!Exists('$(DirPackages)') AND Exists('$(FileNugetConfig)')"
Query="//add[@key='repositorypath']/@value"
XmlInputPath="$(FileNugetConfig)">
<Output
ItemName="DirNuGetPackages"
TaskParameter="Result" />
</XmlPeek>
<!-- If the DirNuGetPackages has a root (i.e. a drive letter) then we assume it is an absolute path. Just use it that way. -->
<CreateProperty
Condition=" '$(DirNuGetPackages)' != '' AND $([System.IO.Path]::IsPathRooted('%(DirNuGetPackages.Identity)'))"
Value="$([System.IO.Path]::GetFullPath('%(DirNuGetPackages.Identity)'))">
<Output
PropertyName="DirPackages"
TaskParameter="Value" />
</CreateProperty>
<!-- If the DirNuGetPackages has no root (i.e. no drive letter) then we assume it is a relative path. Base it on the directory that the nuget.config file is in. -->
<CreateProperty
Condition=" '@(DirNuGetPackages)' != '' AND !$([System.IO.Path]::IsPathRooted('%(DirNuGetPackages.Identity)'))"
Value="$([System.IO.Path]::GetFullPath('$(DirWorkspace)\%(DirNuGetPackages.Identity)'))">
<Output
PropertyName="DirPackages"
TaskParameter="Value" />
</CreateProperty>
<Message
Condition=" '$(DirPackages)' != '' "
Text="Package directory at: $(DirPackages)" />
<!-- No packages folder found. Note this and move on -->
<Warning
Condition=" '$(DirPackages)' == '' "
Text="Unable to find the packages folder." />
</Target>
<!--
Ideally we'd use the NuGetRestore task from nBuildKit, however this task is used to potentially restore the nBuildKit
NuGet package so that we can use the tasks and scripts from nBuildKit ...
In order to prevent it from ever colliding with any of the inline tasks defined elsewhere we'll give it
a name that is unlikely ever to be used elsewhere (yay poor-mans namespaces?).
-->
<UsingTask
AssemblyFile="$(MsBuildTasksAssembly)"
TaskFactory="CodeTaskFactory"
TaskName="EntryPoint_LocalTask_NuGetRestore">
<ParameterGroup>
<NuGetPath
ParameterType="System.String"
Required="true" />
<PackageFile
ParameterType="System.String"
Required="true" />
<PackageDirectory
ParameterType="System.String"
Required="true" />
<Sources
ParameterType="Microsoft.Build.Framework.ITaskItem[]"
Required="false" />
</ParameterGroup>
<Task>
<Reference
Include="System.Xml" />
<Reference
Include="System.Xml.Linq" />
<Code
Language="cs"
Type="Method">
<![CDATA[
public override bool Execute()
{
if (!System.IO.File.Exists(PackageFile))
{
Log.LogMessage(MessageImportance.High, "File does not exist: {0}", PackageFile);
}
var builder = new System.Text.StringBuilder();
{
builder.Append(string.Format("restore \"{0}\" ", PackageFile));
builder.Append("-NonInteractive -Verbosity detailed -NoCache ");
// Make sure we remove the back-slash because if we don't then
// the closing quote will be eaten by the command line parser. Note that
// this is only necessary because we're dealing with a directory
builder.Append(string.Format("-PackagesDirectory \"{0}\" ", PackageDirectory.TrimEnd('\\')));
// If the user has specified any sources to install from then only search those sources.
if (Sources != null)
{
foreach (var source in Sources)
{
// Make sure we remove the back-slash because if we don't then
// the closing quote will be eaten by the command line parser. Note that
// this is only necessary because we're dealing with a directory
builder.Append(string.Format("-Source \"{0}\" ", source.ItemSpec.TrimEnd('\\')));
}
}
}
var info = new System.Diagnostics.ProcessStartInfo
{
FileName = NuGetPath,
Arguments = builder.ToString(),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
};
var process = new System.Diagnostics.Process();
process.StartInfo = info;
process.OutputDataReceived +=
(s, e) =>
{
if (!string.IsNullOrWhiteSpace(e.Data))
{
Log.LogMessage(MessageImportance.Normal, e.Data);
}
};
process.ErrorDataReceived +=
(s, e) =>
{
if (!string.IsNullOrWhiteSpace(e.Data))
{
Log.LogError(e.Data);
}
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
if (process.ExitCode != 0)
{
Log.LogError(
string.Format(
"{0} exited with a non-zero exit code. Exit code was: {1}",
System.IO.Path.GetFileName(process.StartInfo.FileName),
process.ExitCode));
return false;
}
// Log.HasLoggedErrors is true if the task logged any errors -- even if they were logged
// from a task's constructor or property setter. As long as this task is written to always log an error
// when it fails, we can reliably return HasLoggedErrors.
return !Log.HasLoggedErrors;
}
]]>
</Code>
</Task>
</UsingTask>
<!--
In order to prevent this task from ever colliding with any of the inline tasks defined elsewhere we'll give it
a name that is unlikely ever to be used elsewhere (yay poor-mans namespaces?).
-->
<UsingTask
AssemblyFile="$(MsBuildTasksAssembly)"
TaskFactory="CodeTaskFactory"
TaskName="EntryPoint_LocalTask_GetHighestSuitablePackageVersionFromNuGet">
<ParameterGroup>
<NuGetPath
ParameterType="System.String"
Required="true" />
<PackageName
ParameterType="System.String"
Required="true" />
<Sources
ParameterType="Microsoft.Build.Framework.ITaskItem[]"
Required="false" />
<Version
Output="true"
ParameterType="System.String" />
</ParameterGroup>
<Task>
<Code
Language="cs"
Type="Method">
<![CDATA[
public override bool Execute()
{
if ((Sources == null) || (Sources.Length == 0))
{
Log.LogMessage(
MessageImportance.Low,
string.Format(
System.Globalization.CultureInfo.InvariantCulture,
"Getting versions for {0} from default sources",
PackageName));
}
else
{
Log.LogMessage(
MessageImportance.Low,
string.Format(
System.Globalization.CultureInfo.InvariantCulture,
"Getting versions for {0} from: {1} ",
PackageName,
string.Join(", ", Sources.Select(t => t.ItemSpec))));
}
try
{
var builder = new System.Text.StringBuilder();
{
builder.Append(string.Format("list \"{0}\" ", PackageName));
builder.Append("-NonInteractive ");
// If the user has specified any sources to install from then only search those sources.
if (Sources != null)
{
foreach (var source in Sources)
{
// Make sure we remove the back-slash because if we don't then
// the closing quote will be eaten by the command line parser. Note that
// this is only necessary because we're dealing with a directory
builder.Append(string.Format("-Source \"{0}\" ", source.ItemSpec.TrimEnd('\\')));
}
}
}
var info = new System.Diagnostics.ProcessStartInfo
{
FileName = NuGetPath,
Arguments = builder.ToString(),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
};
Log.LogMessage(
MessageImportance.Low,
"Executing {0} with arguments: {1}",
NuGetPath,
info.Arguments);
var text = new System.Collections.Generic.List<string>();
var process = new System.Diagnostics.Process();
process.StartInfo = info;
process.OutputDataReceived +=
(s, e) =>
{
if (!string.IsNullOrWhiteSpace(e.Data))
{
text.Add(e.Data);
}
};
process.ErrorDataReceived +=
(s, e) =>
{
if (!string.IsNullOrWhiteSpace(e.Data))
{
Log.LogError(e.Data);
}
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
if (process.ExitCode != 0)
{
Log.LogError(
string.Format(
"{0} exited with a non-zero exit code. Exit code was: {1}",
System.IO.Path.GetFileName(process.StartInfo.FileName),
process.ExitCode));
return false;
}
Log.LogMessage(
MessageImportance.Low,
"{0} produced the following output: {1}",
NuGetPath,
string.Join(Environment.NewLine, text));
// Expecting something like:
// A 1.2.3
// A.B 1.2.3
// A.C 4.5.6
// A.C.D 7.8.9
// A.E 0.0.1
//
// So find the exact package name by searching for the string that has the package name
// followed by a space
var packageNameInText = PackageName + " ";
string selectedPackage = null;
var selectedVersion = new Version();
foreach(var line in text)
{
if (line.StartsWith(packageNameInText))
{
var versionText = line.Substring(packageNameInText.Length);
System.Version packageVersion;
if (!System.Version.TryParse(versionText, out packageVersion))
{
Log.LogMessage(
MessageImportance.Low,
"Package {0} is not a match for package {1}",
line,
PackageName);
continue;
}
if (packageVersion > selectedVersion)
{
Log.LogMessage(
MessageImportance.Low,
"Path {0} is a better match for package {1} than {2}",
line,
PackageName,
selectedPackage);
selectedVersion = packageVersion;
selectedPackage = line;
}
}
}
if (string.IsNullOrEmpty(selectedPackage))
{
Log.LogError("Failed to find the correct package version.");
return false;
}
Version = selectedVersion.ToString(3);
}
catch(Exception e)
{
Log.LogError(e.ToString());
}
// Log.HasLoggedErrors is true if the task logged any errors -- even if they were logged
// from a task's constructor or property setter. As long as this task is written to always log an error
// when it fails, we can reliably return HasLoggedErrors.
return !Log.HasLoggedErrors;
}
]]>
</Code>
</Task>
</UsingTask>
<!--
In order to prevent this task from ever colliding with any of the inline tasks defined elsewhere we'll give it
a name that is unlikely ever to be used elsewhere (yay poor-mans namespaces?).
-->
<UsingTask
AssemblyFile="$(MsBuildTasksAssembly)"
TaskFactory="CodeTaskFactory"
TaskName="EntryPoint_LocalTask_InstallPackageFromNuGet">
<ParameterGroup>
<NuGetPath
ParameterType="System.String"
Required="true" />
<PackageDirectory
ParameterType="System.String"
Required="true" />
<PackageName
ParameterType="System.String"
Required="true" />
<PackageVersion
ParameterType="System.String"
Required="true" />
<Sources
ParameterType="Microsoft.Build.Framework.ITaskItem[]"
Required="false" />
</ParameterGroup>
<Task>
<Code
Language="cs"
Type="Method">
<![CDATA[
public override bool Execute()
{
var builder = new System.Text.StringBuilder();
{
builder.Append(string.Format("install \"{0}\" ", PackageName));
builder.Append(string.Format("-Version \"{0}\" ", PackageVersion));
builder.Append("-NonInteractive -ExcludeVersion -Verbosity detailed -NoCache ");
// Make sure we remove the back-slash because if we don't then
// the closing quote will be eaten by the command line parser. Note that
// this is only necessary because we're dealing with a directory
builder.Append(string.Format("-OutputDirectory \"{0}\" ", PackageDirectory.TrimEnd('\\')));
// If the user has specified any sources to install from then only search those sources.
if (Sources != null)
{
foreach (var source in Sources)
{
// Make sure we remove the back-slash because if we don't then
// the closing quote will be eaten by the command line parser. Note that
// this is only necessary because we're dealing with a directory
builder.Append(string.Format("-Source \"{0}\" ", source.ItemSpec.TrimEnd('\\')));
}
}
}
var info = new System.Diagnostics.ProcessStartInfo
{
FileName = NuGetPath,
Arguments = builder.ToString(),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
};
var process = new System.Diagnostics.Process();
process.StartInfo = info;
process.OutputDataReceived +=
(s, e) =>
{
if (!string.IsNullOrWhiteSpace(e.Data))
{
Log.LogMessage(MessageImportance.Normal, e.Data);
}
};
process.ErrorDataReceived +=
(s, e) =>
{
if (!string.IsNullOrWhiteSpace(e.Data))
{
Log.LogError(e.Data);
}
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
if (process.ExitCode != 0)
{
Log.LogError(
string.Format(
"{0} exited with a non-zero exit code. Exit code was: {1}",
System.IO.Path.GetFileName(process.StartInfo.FileName),
process.ExitCode));
return false;
}
// Log.HasLoggedErrors is true if the task logged any errors -- even if they were logged
// from a task's constructor or property setter. As long as this task is written to always log an error
// when it fails, we can reliably return HasLoggedErrors.
return !Log.HasLoggedErrors;
}
]]>
</Code>
</Task>
</UsingTask>
<!--
*****************************************
* *
* NBUILDKIT SPECIFIC SETTINGS *
* *
*****************************************
-->
<PropertyGroup>
<OpsToolsBuildEntryPointVersion>$VersionOpsTools$</OpsToolsBuildEntryPointVersion>
</PropertyGroup>
</Project>