-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEgonsoftHU.NuspecProperties.targets
158 lines (128 loc) · 7 KB
/
EgonsoftHU.NuspecProperties.targets
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
<!--
Copyright © 2022 Gabor Csizmadia
This code is licensed under MIT license (see LICENSE for details)
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="15.0">
<UsingTask
TaskName="EgonsoftHU_UpdateNuspecFile"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<NuspecFilePath Required="True" />
<Owners />
<Summary />
</ParameterGroup>
<Task>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Using Namespace="System" />
<Using Namespace="System.Xml.Linq" />
<Code Type="Fragment" Language="cs">
<![CDATA[
Log.LogMessage(MessageImportance.High, "");
if (File.Exists(NuspecFilePath))
{
Log.LogMessage(MessageImportance.High, "The .nuspec file was found.");
}
else
{
Log.LogError("Could not find .nuspec file.");
return false;
}
bool hasOwners = !String.IsNullOrWhiteSpace(Owners);
bool hasSummary = !String.IsNullOrWhiteSpace(Summary);
if (!hasOwners && !hasSummary)
{
Log.LogWarning("Both Owners and Summary MSBuild properties are empty. The .nuspec file will be unmodified.");
return false;
}
Log.LogMessage(MessageImportance.High, "Loading .nuspec file...");
var nuspec = XDocument.Load(NuspecFilePath);
Log.LogMessage(MessageImportance.High, "Getting default XML namespace...");
string xsdNamespace = nuspec.Root.GetDefaultNamespace().NamespaceName;
Log.LogMessage(MessageImportance.High, "Getting <metadata> node...");
var metadataNode = nuspec.Root.Descendants(XName.Get("metadata", xsdNamespace)).Single();
if (hasOwners)
{
Log.LogMessage(MessageImportance.High, "Getting <authors> node...");
var authorsNode = metadataNode.Descendants(XName.Get("authors", xsdNamespace)).Single();
Log.LogMessage(MessageImportance.High, "Appending <owners> node...");
authorsNode.AddAfterSelf(new XElement(XName.Get("owners", xsdNamespace)) { Value = Owners });
}
if (hasSummary)
{
Log.LogMessage(MessageImportance.High, "Getting <description> node...");
var descriptionNode = metadataNode.Descendants(XName.Get("description", xsdNamespace)).Single();
Log.LogMessage(MessageImportance.High, "Appending <summary> node...");
descriptionNode.AddAfterSelf(new XElement(XName.Get("summary", xsdNamespace)) { Value = Summary });
}
Log.LogMessage(MessageImportance.High, "Saving .nuspec file...");
nuspec.Save(NuspecFilePath);
return true;
]]>
</Code>
</Task>
</UsingTask>
<Target Name="EgonsoftHU_UpdateNupkgFile" AfterTargets="Pack">
<PropertyGroup>
<PackageOutputPath Condition="$(PackageOutputPath) != ''">$([System.IO.Path]::GetFullPath('$(PackageOutputPath)'))</PackageOutputPath>
<EgonsoftHU_NupkgFileName>$(PackageId).$(PackageVersion).nupkg</EgonsoftHU_NupkgFileName>
<EgonsoftHU_NupkgFilePath>$([System.IO.Path]::Combine('$(PackageOutputPath)', '$(EgonsoftHU_NupkgFileName)'))</EgonsoftHU_NupkgFilePath>
<EgonsoftHU_TempFolderName>$([System.Guid]::NewGuid().ToString('D'))</EgonsoftHU_TempFolderName>
<EgonsoftHU_TempFolderPath>$([System.IO.Path]::Combine('$(PackageOutputPath)', '$(EgonsoftHU_TempFolderName)'))</EgonsoftHU_TempFolderPath>
<EgonsoftHU_NuspecFileName>$(PackageId).nuspec</EgonsoftHU_NuspecFileName>
<EgonsoftHU_NuspecFilePath>$([System.IO.Path]::Combine('$(EgonsoftHU_TempFolderPath)', '$(EgonsoftHU_NuspecFileName)'))</EgonsoftHU_NuspecFilePath>
</PropertyGroup>
<Message Importance="high" Text=" " />
<Message Importance="high" Text="======================================" />
<Message Importance="high" Text="Egonsoft.HU NuGet package updater v1.0" />
<Message Importance="high" Text="======================================" />
<Message Importance="high" Text="Author : Gabor Csizmadia" />
<Message Importance="high" Text="Description : Update .nuspec file by adding owners and summary elements using Owners and Summary MSBuild properties." />
<Message Importance="high" Text="--------------------------------------" />
<Message Importance="high" Text="Creating temporary folder..." />
<Message Importance="high" Text=" Folder : [$(EgonsoftHU_TempFolderPath)]" />
<MakeDir
Directories="$(EgonsoftHU_TempFolderPath)"
/>
<Message Importance="high" Text="--------------------------------------" />
<Message Importance="high" Text="Unzipping .nupkg file to the temporary folder..." />
<Message Importance="high" Text=" .nupkg file : [$(EgonsoftHU_NupkgFilePath)]" />
<Message Importance="high" Text=" Folder : [$(EgonsoftHU_TempFolderPath)]" />
<Unzip
SourceFiles="$(EgonsoftHU_NupkgFilePath)"
DestinationFolder="$(EgonsoftHU_TempFolderPath)"
/>
<Message Importance="high" Text="--------------------------------------" />
<Message Importance="high" Text="Updating .nuspec file..." />
<Message Importance="high" Text=" .nuspec file: [$(EgonsoftHU_NuspecFilePath)]" />
<Message Importance="high" Text=" Owners : [$(Owners)]" />
<Message Importance="high" Text=" Summary : [$(Summary)]" />
<EgonsoftHU_UpdateNuspecFile
NuspecFilePath="$(EgonsoftHU_NuspecFilePath)"
Owners="$(Owners)"
Summary="$(Summary)"
/>
<Message Importance="high" Text="--------------------------------------" />
<Message Importance="high" Text="Creating new .nupkg file from the contents of the temporary folder..." />
<Message Importance="high" Text=" .nupkg file : [$(EgonsoftHU_NupkgFilePath)]" />
<Message Importance="high" Text=" Folder : [$(EgonsoftHU_TempFolderPath)]" />
<Message Importance="high" Text=" " />
<ZipDirectory
SourceDirectory="$(EgonsoftHU_TempFolderPath)"
DestinationFile="$(EgonsoftHU_NupkgFilePath)"
Overwrite="True"
/>
<Message Importance="high" Text="--------------------------------------" />
<Message Importance="high" Text="Deleting temporary folder..." />
<Message Importance="high" Text=" Folder : [$(EgonsoftHU_TempFolderPath)]" />
<RemoveDir
Directories="$(EgonsoftHU_TempFolderPath)"
/>
<Message Importance="high" Text="--------------------------------------" />
<Message Importance="high" Text="The new .nupkg file has been created..." />
<Message Importance="high" Text=" .nupkg file : [$(EgonsoftHU_NupkgFilePath)]" />
<Message Importance="high" Text="======================================" />
</Target>
</Project>