Skip to content

Commit 71068c2

Browse files
dannyvarod_cpdannyvarod_cp
dannyvarod_cp
authored and
dannyvarod_cp
committed
v2.4: Added more config file options.
git-tfs-id: [https://tfs.codeplex.com/tfs/tfs27]$/pubcomp/Building;C29163
1 parent 6dbe0fd commit 71068c2

File tree

5 files changed

+243
-36
lines changed

5 files changed

+243
-36
lines changed

Demo.Package2.NuGet/NuGetPack.config

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
<NuGetPack>
22
<AddFrameworkReferences>true</AddFrameworkReferences>
33
<IconUrl>http://www.codeplex.com/favicon.ico</IconUrl>
4+
<ProjectUrl>https://pubcomp.codeplex.com/#</ProjectUrl>
5+
<LicenseUrl>https://pubcomp.codeplex.com/license</LicenseUrl>
6+
<Authors>Demo Author</Authors>
7+
<Owners>Demo Owner</Owners>
8+
<Copyright>Demo Copyright</Copyright>
9+
<Description>Demo Description</Description>
10+
<Summary>Demo Summary</Summary>
11+
<Keywords>Demo, Key, Word</Keywords>
412
</NuGetPack>

NuGetPack.UnitTests/NuGetPackTests.cs

+128-3
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ public void TestCreatePackage2()
376376

377377
#region Package Metadata Tests
378378

379+
#region From Assembly Metadata
380+
379381
[TestMethod]
380382
public void TestParseVersion()
381383
{
@@ -407,7 +409,7 @@ public void TestParseName()
407409
}
408410

409411
[TestMethod]
410-
public void TestParseDescription()
412+
public void TestParseDescriptionFromAssembly()
411413
{
412414
var creator = new NuspecCreator();
413415
var nuspec = creator.CreateNuspec(nuProj1Csproj, nuProj1Dll, isDebug);
@@ -420,7 +422,7 @@ public void TestParseDescription()
420422
}
421423

422424
[TestMethod]
423-
public void TestParseTags()
425+
public void TestParseKeywordsFromAssembly()
424426
{
425427
var creator = new NuspecCreator();
426428
var nuspec = creator.CreateNuspec(nuProj1Csproj, nuProj1Dll, isDebug);
@@ -433,7 +435,7 @@ public void TestParseTags()
433435
}
434436

435437
[TestMethod]
436-
public void TestParseProjectUrl()
438+
public void TestParseProjectUrlFromAssembly()
437439
{
438440
var creator = new NuspecCreator();
439441
var nuspec = creator.CreateNuspec(nuProj1Csproj, nuProj1Dll, isDebug);
@@ -447,6 +449,129 @@ public void TestParseProjectUrl()
447449

448450
#endregion
449451

452+
#region From Config file
453+
454+
[TestMethod]
455+
public void TestParseDescriptionFromConfig()
456+
{
457+
var creator = new NuspecCreator();
458+
var nuspec = creator.CreateNuspec(nuProj2Csproj, nuProj2Dll, isDebug);
459+
460+
Assert.IsNotNull(nuspec);
461+
462+
var version = nuspec.XPathSelectElement(@"/package/metadata/description").Value;
463+
464+
Assert.AreEqual("Demo Description", version);
465+
}
466+
467+
[TestMethod]
468+
public void TestParseSummaryFromConfig()
469+
{
470+
var creator = new NuspecCreator();
471+
var nuspec = creator.CreateNuspec(nuProj2Csproj, nuProj2Dll, isDebug);
472+
473+
Assert.IsNotNull(nuspec);
474+
475+
var version = nuspec.XPathSelectElement(@"/package/metadata/summary").Value;
476+
477+
Assert.AreEqual("Demo Summary", version);
478+
}
479+
480+
[TestMethod]
481+
public void TestParseKeywordsFromConfig()
482+
{
483+
var creator = new NuspecCreator();
484+
var nuspec = creator.CreateNuspec(nuProj2Csproj, nuProj2Dll, isDebug);
485+
486+
Assert.IsNotNull(nuspec);
487+
488+
var version = nuspec.XPathSelectElement(@"/package/metadata/tags").Value;
489+
490+
Assert.AreEqual("Demo, Key, Word", version);
491+
}
492+
493+
[TestMethod]
494+
public void TestParseIconUrlFromConfig()
495+
{
496+
var creator = new NuspecCreator();
497+
var nuspec = creator.CreateNuspec(nuProj2Csproj, nuProj2Dll, isDebug);
498+
499+
Assert.IsNotNull(nuspec);
500+
501+
var version = nuspec.XPathSelectElement(@"/package/metadata/iconUrl").Value;
502+
503+
Assert.AreEqual("http://www.codeplex.com/favicon.ico", version);
504+
}
505+
506+
[TestMethod]
507+
public void TestParseProjectUrlFromConfig()
508+
{
509+
var creator = new NuspecCreator();
510+
var nuspec = creator.CreateNuspec(nuProj2Csproj, nuProj2Dll, isDebug);
511+
512+
Assert.IsNotNull(nuspec);
513+
514+
var version = nuspec.XPathSelectElement(@"/package/metadata/projectUrl").Value;
515+
516+
Assert.AreEqual("https://pubcomp.codeplex.com/#", version);
517+
}
518+
519+
[TestMethod]
520+
public void TestParseLicenseUrlFromConfig()
521+
{
522+
var creator = new NuspecCreator();
523+
var nuspec = creator.CreateNuspec(nuProj2Csproj, nuProj2Dll, isDebug);
524+
525+
Assert.IsNotNull(nuspec);
526+
527+
var version = nuspec.XPathSelectElement(@"/package/metadata/licenseUrl").Value;
528+
529+
Assert.AreEqual("https://pubcomp.codeplex.com/license", version);
530+
}
531+
532+
[TestMethod]
533+
public void TestParseAuthorsFromConfig()
534+
{
535+
var creator = new NuspecCreator();
536+
var nuspec = creator.CreateNuspec(nuProj2Csproj, nuProj2Dll, isDebug);
537+
538+
Assert.IsNotNull(nuspec);
539+
540+
var version = nuspec.XPathSelectElement(@"/package/metadata/authors").Value;
541+
542+
Assert.AreEqual("Demo Author", version);
543+
}
544+
545+
[TestMethod]
546+
public void TestParseOwnersFromConfig()
547+
{
548+
var creator = new NuspecCreator();
549+
var nuspec = creator.CreateNuspec(nuProj2Csproj, nuProj2Dll, isDebug);
550+
551+
Assert.IsNotNull(nuspec);
552+
553+
var version = nuspec.XPathSelectElement(@"/package/metadata/owners").Value;
554+
555+
Assert.AreEqual("Demo Owner", version);
556+
}
557+
558+
[TestMethod]
559+
public void TestParseCopyrightFromConfig()
560+
{
561+
var creator = new NuspecCreator();
562+
var nuspec = creator.CreateNuspec(nuProj2Csproj, nuProj2Dll, isDebug);
563+
564+
Assert.IsNotNull(nuspec);
565+
566+
var version = nuspec.XPathSelectElement(@"/package/metadata/copyright").Value;
567+
568+
Assert.AreEqual("Demo Copyright", version);
569+
}
570+
571+
#endregion
572+
573+
#endregion
574+
450575
#region Command-line Tests
451576

452577
[TestMethod]

NuGetPack/NuGetPackConfig.cs

+47
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,54 @@ namespace PubComp.Building.NuGetPack
1010
[System.Xml.Serialization.XmlType("NuGetPack", Namespace=null)]
1111
public class NuGetPackConfig
1212
{
13+
/// <summary>
14+
/// Optional, if set to true adds framework references from NuGet project to NuGet package
15+
/// </summary>
1316
public bool AddFrameworkReferences { get; set; }
17+
18+
/// <summary>
19+
/// Optional, if set to non-empty value, sets NuGet package icon, otherwise uses default
20+
/// </summary>
1421
public string IconUrl { get; set; }
22+
23+
/// <summary>
24+
/// Optional, if not set (or if empty), value is taken from NuGet project's AssemblyInfo (from AssemblyTrademark)
25+
/// </summary>
26+
public string ProjectUrl { get; set; }
27+
28+
/// <summary>
29+
/// Optional, if not set (or if empty), value is taken from NuGet project's AssemblyInfo (from AssemblyTrademark)
30+
/// </summary>
31+
public string LicenseUrl { get; set; }
32+
33+
/// <summary>
34+
/// Optional, if not set (or if empty), value is taken from NuGet project's AssemblyInfo (from AssemblyCompany)
35+
/// </summary>
36+
public string Authors { get; set; }
37+
38+
/// <summary>
39+
/// Optional, if not set (or if empty), value is taken from NuGet project's AssemblyInfo (from AssemblyCompany)
40+
/// </summary>
41+
public string Owners { get; set; }
42+
43+
/// <summary>
44+
/// Optional, if not set (or if empty), value is taken from NuGet project's AssemblyInfo (from AssemblyCopyright)
45+
/// </summary>
46+
public string Copyright { get; set; }
47+
48+
/// <summary>
49+
/// Optional, if not set (or if empty), value is taken from NuGet project's AssemblyInfo (from AssemblyDescription)
50+
/// </summary>
51+
public string Description { get; set; }
52+
53+
/// <summary>
54+
/// Optional, if not set (or if empty), value is taken from NuGet project's AssemblyInfo (from AssemblyDescription)
55+
/// </summary>
56+
public string Summary { get; set; }
57+
58+
/// <summary>
59+
/// Optional, if not set (or if empty), value is taken from NuGet project's AssemblyInfo (from AssemblyTitle)
60+
/// </summary>
61+
public string Keywords { get; set; }
1562
}
1663
}

NuGetPack/NuspecCreator.cs

+58-31
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ public XDocument CreateNuspec(string projectPath, string assemblyPath, bool isDe
109109
if (fileVersion.ProductVersion.Contains("-"))
110110
version += "-" + "PreRelease";
111111

112-
var owner = fileVersion.CompanyName;
112+
var owners = fileVersion.CompanyName;
113113

114114
var shortSummary = fileVersion.Comments;
115115
var longDescription = fileVersion.Comments;
116116
var copyright = fileVersion.LegalCopyright;
117117
var releaseNotes = fileVersion.SpecialBuild;
118-
var tags = fileVersion.FileDescription;
118+
var keywords = fileVersion.FileDescription;
119119
var licenseUrl = fileVersion.LegalTrademarks;
120120
var projectUrl = fileVersion.LegalTrademarks;
121121

@@ -126,48 +126,79 @@ public XDocument CreateNuspec(string projectPath, string assemblyPath, bool isDe
126126

127127
var nuspecPath = Path.ChangeExtension(assemblyPath, ".nuspec");
128128

129+
130+
string iconUrl = @"https://nuget.org/Content/Images/packageDefaultIcon-50x50.png";
131+
bool doAddFrameworkReferences = false;
132+
string authors = owners;
133+
134+
if (File.Exists(configFile))
135+
{
136+
var deserializer = new System.Xml.Serialization.XmlSerializer(typeof(NuGetPackConfig));
137+
using (var stream = new FileStream(configFile, FileMode.Open, FileAccess.Read))
138+
{
139+
var config = deserializer.Deserialize(stream) as NuGetPackConfig;
140+
141+
doAddFrameworkReferences = config.AddFrameworkReferences;
142+
143+
if (!string.IsNullOrEmpty(config.Authors))
144+
authors = config.Authors;
145+
146+
if (!string.IsNullOrEmpty(config.Copyright))
147+
copyright = config.Copyright;
148+
149+
if (!string.IsNullOrEmpty(config.Description))
150+
longDescription = config.Description;
151+
152+
if (!string.IsNullOrEmpty(config.IconUrl))
153+
iconUrl = config.IconUrl;
154+
155+
if (!string.IsNullOrEmpty(config.Keywords))
156+
keywords = config.Keywords;
157+
158+
if (!string.IsNullOrEmpty(config.LicenseUrl))
159+
licenseUrl = config.LicenseUrl;
160+
161+
if (!string.IsNullOrEmpty(config.Owners))
162+
owners = config.Owners;
163+
164+
if (!string.IsNullOrEmpty(config.ProjectUrl))
165+
projectUrl = config.ProjectUrl;
166+
167+
if (!string.IsNullOrEmpty(config.Summary))
168+
shortSummary = config.Summary;
169+
}
170+
}
171+
129172
var doc = CreateNuspec(
130-
packageName, version, owner, shortSummary,
131-
longDescription, releaseNotes, licenseUrl, projectUrl, copyright, tags, nuspecPath, projectPath,
132-
packagesFile, internalPackagesFile, configFile, isDebug);
173+
packageName, version, owners, authors, shortSummary,
174+
longDescription, releaseNotes, licenseUrl, projectUrl, iconUrl, copyright, keywords, nuspecPath, projectPath,
175+
packagesFile, internalPackagesFile, isDebug, doAddFrameworkReferences);
133176

134177
return doc;
135178
}
136179

137180
public XDocument CreateNuspec(
138181
string packageName,
139182
string version,
140-
string owner,
183+
string owners,
184+
string authors,
141185
string shortSummary,
142186
string longDescription,
143187
string releaseNotes,
144188
string licenseUrl,
145189
string projectUrl,
190+
string iconUrl,
146191
string copyright,
147-
string tags,
192+
string keywords,
148193
string nuspecPath,
149194
string projectPath,
150195
string packagesFile,
151196
string internalPackagesFile,
152-
string configPath,
153-
bool isDebug)
197+
bool isDebug,
198+
bool doAddFrameworkReferences)
154199
{
155200
var nuspecFolder = Path.GetDirectoryName(nuspecPath);
156201

157-
string iconUrl = null;
158-
bool addFrameworkReferences = false;
159-
160-
if (File.Exists(configPath))
161-
{
162-
var deserializer = new System.Xml.Serialization.XmlSerializer(typeof(NuGetPackConfig));
163-
using (var stream = new FileStream(configPath, FileMode.Open, FileAccess.Read))
164-
{
165-
var config = deserializer.Deserialize(stream) as NuGetPackConfig;
166-
iconUrl = config.IconUrl;
167-
addFrameworkReferences = config.AddFrameworkReferences;
168-
}
169-
}
170-
171202
XAttribute dependenciesAttribute;
172203
var dependenciesInfo = GetDependencies(new[] { packagesFile, internalPackagesFile }, out dependenciesAttribute);
173204
var elements = GetElements(nuspecFolder, projectPath, isDebug);
@@ -195,17 +226,13 @@ public XDocument CreateNuspec(
195226
&& el.ElementType != ElementType.NuGetDependency
196227
&& el.ElementType != ElementType.FrameworkReference)
197228
.Select(el => el.Element).ToList();
198-
199-
iconUrl = !string.IsNullOrEmpty(iconUrl) ?
200-
iconUrl
201-
: @"https://nuget.org/Content/Images/packageDefaultIcon-50x50.png";
202229

203230
var metadataElement = new XElement("metadata",
204231
new XElement("id", packageName),
205232
new XElement("version", version),
206233
new XElement("title", packageName),
207-
new XElement("authors", owner),
208-
new XElement("owners", owner),
234+
new XElement("authors", authors),
235+
new XElement("owners", owners),
209236
new XElement("description", longDescription),
210237
new XElement("releaseNotes", releaseNotes),
211238
new XElement("summary", shortSummary),
@@ -217,9 +244,9 @@ public XDocument CreateNuspec(
217244
new XElement("copyright", copyright),
218245
new XElement("dependencies", dependencies),
219246
new XElement("references", string.Empty),
220-
new XElement("tags", tags));
247+
new XElement("tags", keywords));
221248

222-
if (addFrameworkReferences)
249+
if (doAddFrameworkReferences)
223250
{
224251
var frameworkReferences = GetFrameworkReferences(Path.GetDirectoryName(projectPath), projectPath)
225252
.Select(el => el.Element)

VersionInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
using System.Runtime.CompilerServices;
33
using System.Runtime.InteropServices;
44

5-
[assembly: AssemblyVersion("2.3.0.0")]
6-
[assembly: AssemblyFileVersion("2.3.0.0")]
5+
[assembly: AssemblyVersion("2.4.0.0")]
6+
[assembly: AssemblyFileVersion("2.4.0.0")]

0 commit comments

Comments
 (0)