1
+ <?xml version =" 1.0" encoding =" utf-8" ?>
2
+ <!-- This file builds the Enterprise Library Application Blocks -->
3
+ <!-- and runs the unit tests. -->
4
+ <Project xmlns =" http://schemas.microsoft.com/developer/msbuild/2003"
5
+ ToolsVersion =" 4.0" >
6
+
7
+ <PropertyGroup >
8
+ <NuGetExeDirectory >$(MSBuildThisFileDirectory)bin\</NuGetExeDirectory >
9
+ <NuGetExePath >$(NuGetExeDirectory)nuget.exe</NuGetExePath >
10
+ <BuildNugetPackages >true</BuildNugetPackages >
11
+ </PropertyGroup >
12
+
13
+ <ItemGroup >
14
+ <NuSpecFiles Include =" $(SourceRoot)**\*.nuspec" Exclude =" $(SourceRoot)packages\**\*.nuspec" />
15
+ </ItemGroup >
16
+
17
+ <Target Name =" RestoreNugetPackages" DependsOnTargets =" _DownloadNuGet" >
18
+ <Exec Command =" " $(NuGetExePath)" restore " %(Solutions.FullPath)" -NonInteractive" />
19
+ <Exec Command =" " $(NuGetExePath)" restore packages.config -PackagesDirectory packages -NonInteractive" />
20
+ </Target >
21
+
22
+ <Target Name =" BuildNugetPackages" DependsOnTargets =" _DownloadNuget;_GetPackageVersions;_BuildPackageVersionTokens"
23
+ Condition =" '$(BuildNugetPackages)' == 'true' "
24
+ Inputs =" @(NuSpecFiles)" Outputs =" %(NuSpecFiles.Identity)-runalways" >
25
+
26
+ <PropertyGroup >
27
+ <SourceRootFullPath >$([System.IO.Path]::GetFullPath('$(SourceRoot)'))</SourceRootFullPath >
28
+ <PackageBasePath >$(SourceRootFullPath.TrimEnd('\'))</PackageBasePath >
29
+ <PackageOutputDir Condition =" '$(PackageOutputDir)' == '' " >$([System.IO.Path]::GetFullPath('$(RepoRoot)bin\$(Configuration)\Nuget'))</PackageOutputDir >
30
+ </PropertyGroup >
31
+
32
+ <PropertyGroup >
33
+ <_NuGetPackTarget >$([System.IO.Path]::GetDirectoryName("%(NuSpecFiles.FullPath)"))\%(NuSpecFiles.Filename).csproj</_NuGetPackTarget >
34
+ <_NuGetPackTarget Condition =" !Exists('$(_NuGetPackTarget)') " >%(NuSpecFiles.FullPath)</_NuGetPackTarget >
35
+ </PropertyGroup >
36
+
37
+ <MakeDir Directories =" $(PackageOutputDir)" Condition =" !Exists($(PackageOutputDir))" />
38
+
39
+ <Exec Command =" " $(NuGetExePath)" pack " $(_NuGetPackTarget)" -Properties Configuration=$(Configuration);@(_VersionTokens) -NonInteractive -OutputDirectory " $(PackageOutputDir)" -Symbols -BasePath " $(PackageBasePath)" "
40
+ IgnoreStandardErrorWarningFormat =" true" />
41
+
42
+ </Target >
43
+
44
+ <Target Name =" CleanNugetPackages" >
45
+
46
+ <PropertyGroup >
47
+ <PackageOutputDir Condition =" '$(PackageOutputDir)' == '' " >$([System.IO.Path]::GetFullPath('$(RepoRoot)bin\$(Configuration)\Nuget'))</PackageOutputDir >
48
+ </PropertyGroup >
49
+
50
+ <ItemGroup >
51
+ <Packages Include =" $(PackageOutputDir)\*.nupkg" />
52
+ </ItemGroup >
53
+
54
+ <Message Text =" @(Packages)" />
55
+ <Delete Files =" @(Packages)" />
56
+
57
+ </Target >
58
+
59
+ <Target Name =" _GetPackageVersions" >
60
+
61
+ <ItemGroup >
62
+ <OutputBinaries Include =" $(OutputRoot)*.dll;$(OutputRoot)*.exe" />
63
+ </ItemGroup >
64
+
65
+ <GetAssemblyVersion VersionProviderPaths =" @(OutputBinaries)" >
66
+ <Output TaskParameter =" Versions" ItemName =" AssemblyVersions" />
67
+ </GetAssemblyVersion >
68
+
69
+ <Message Importance =" high" Text =" Versions found: @(AssemblyVersions)" />
70
+
71
+ </Target >
72
+
73
+ <Target Name =" _BuildPackageVersionTokens" Inputs =" @(AssemblyVersions)" Outputs =" %(Identity)" >
74
+ <!-- Using target batching to be able to do transformations on the metadata values -->
75
+ <PropertyGroup >
76
+ <AssemblyToken >%(AssemblyVersions.Identity)</AssemblyToken >
77
+ <AssemblyToken >$(AssemblyToken.Replace(".", "_"))</AssemblyToken >
78
+ <AssemblyToken >$(AssemblyToken.Replace("-", "_"))</AssemblyToken >
79
+ </PropertyGroup >
80
+
81
+ <ItemGroup >
82
+ <_VersionTokens Include =" $(VersionTokens)$(AssemblyToken)_Version=%(AssemblyVersions.InformationalVersion)" />
83
+ </ItemGroup >
84
+ </Target >
85
+
86
+ <Target Name =" _DownloadNuGet" Condition =" !Exists('$(NuGetExePath)')" >
87
+ <MakeDir Directories =" $(NuGetExeDirectory)" Condition =" !Exists('$(NuGetExeDirectory)')" />
88
+ <DownloadNuGet OutputFilename =" $(NuGetExePath)" />
89
+ </Target >
90
+
91
+ <UsingTask TaskName =" DownloadNuGet" TaskFactory =" CodeTaskFactory" AssemblyFile =" $(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
92
+ <ParameterGroup >
93
+ <OutputFilename ParameterType =" System.String" Required =" true" />
94
+ </ParameterGroup >
95
+ <Task >
96
+ <Reference Include =" System.Core" />
97
+ <Using Namespace =" System" />
98
+ <Using Namespace =" System.IO" />
99
+ <Using Namespace =" System.Net" />
100
+ <Using Namespace =" Microsoft.Build.Framework" />
101
+ <Using Namespace =" Microsoft.Build.Utilities" />
102
+ <Code Type =" Fragment" Language =" cs" >
103
+ <![CDATA[
104
+ try
105
+ {
106
+ OutputFilename = Path.GetFullPath(OutputFilename);
107
+
108
+ Log.LogMessage("Downloading latest version of NuGet.exe to " + OutputFilename);
109
+ WebClient webClient = new WebClient();
110
+ webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename);
111
+
112
+ return true;
113
+ }
114
+ catch (Exception ex) {
115
+ Log.LogErrorFromException(ex);
116
+ return false;
117
+ }
118
+ ]]>
119
+ </Code >
120
+ </Task >
121
+ </UsingTask >
122
+
123
+ <UsingTask TaskName =" GetAssemblyVersion" TaskFactory =" CodeTaskFactory" AssemblyFile =" $(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
124
+ <ParameterGroup >
125
+ <VersionProviderPaths ParameterType =" Microsoft.Build.Framework.ITaskItem[]" Required =" true" />
126
+ <Versions ParameterType =" Microsoft.Build.Framework.ITaskItem[]" Output =" true" />
127
+ </ParameterGroup >
128
+ <Task >
129
+ <Using Namespace =" System" />
130
+ <Using Namespace =" System.Reflection" />
131
+ <Using Namespace =" Microsoft.Build.Framework" />
132
+ <Using Namespace =" Microsoft.Build.Utilities" />
133
+ <Code Type =" Fragment" Language =" cs" >
134
+ <![CDATA[
135
+ var versions = new List<ITaskItem>();
136
+ try
137
+ {
138
+ foreach(var versionProviderPath in VersionProviderPaths)
139
+ {
140
+ var assembly = Assembly.LoadFrom(versionProviderPath.GetMetadata("Fullpath"));
141
+ var assemblyName = assembly.GetName();
142
+ var version = assemblyName.Version;
143
+ var fileVersionAttribute = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>();
144
+ var informationalVersionAttribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
145
+
146
+ var item = new TaskItem(assemblyName.Name);
147
+ item.SetMetadata("AssemblyVersion", version.ToString());
148
+ item.SetMetadata("FileVersion", fileVersionAttribute != null ? fileVersionAttribute.Version : string.Empty);
149
+ item.SetMetadata("InformationalVersion", informationalVersionAttribute != null ? informationalVersionAttribute.InformationalVersion : string.Empty);
150
+
151
+ versions.Add(item);
152
+ }
153
+
154
+ Versions = versions.ToArray();
155
+ return true;
156
+ }
157
+ catch (Exception ex) {
158
+ Log.LogErrorFromException(ex);
159
+ return false;
160
+ }
161
+ ]]>
162
+ </Code >
163
+ </Task >
164
+ </UsingTask >
165
+
166
+ </Project >
0 commit comments