Skip to content

Commit 16c01d5

Browse files
authored
Merge branch 'release/2.2' => 'master' (#10023)
2 parents 3dbbb29 + 82a68ea commit 16c01d5

File tree

5 files changed

+237
-36
lines changed

5 files changed

+237
-36
lines changed

build/sources.props

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@
2727
$(RestoreSources);
2828
https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json;
2929
</RestoreSources>
30-
<!-- Only used to fetch Microsoft.NETFramework.ReferenceAssemblies for x-plat netfx builds. -->
31-
<RestoreSources Condition=" '$(OS)' != 'Windows_NT' ">
32-
$(RestoreSources);
33-
https://dotnet.myget.org/F/roslyn-tools/api/v3/index.json;
34-
</RestoreSources>
3530

3631
<!-- In an orchestrated build, this may be overriden to other Azure feeds. -->
3732
<DotNetAssetRootUrl Condition="'$(DotNetAssetRootUrl)'==''">https://dotnetcli.blob.core.windows.net/dotnet/</DotNetAssetRootUrl>

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
<!-- Build tool dependencies -->
133133
<InternalAspNetCoreSdkPackageVersion>$(KoreBuildVersion)</InternalAspNetCoreSdkPackageVersion>
134134
<InternalAspNetCoreSdkPackageVersion Condition=" '$(KoreBuildVersion)' == '' ">3.0.0-build-20190430.1</InternalAspNetCoreSdkPackageVersion>
135-
<MicrosoftNETFrameworkReferenceAssembliesPackageVersion>1.0.0-alpha-004</MicrosoftNETFrameworkReferenceAssembliesPackageVersion>
135+
<MicrosoftNETFrameworkReferenceAssembliesPackageVersion>1.0.0-preview.1</MicrosoftNETFrameworkReferenceAssembliesPackageVersion>
136136
<MicrosoftNETTestSdkPackageVersion>15.9.0</MicrosoftNETTestSdkPackageVersion>
137137
<MicrosoftSourceLinkGitHubPackageVersion>1.0.0-beta2-18618-05</MicrosoftSourceLinkGitHubPackageVersion>
138138
<MicrosoftSourceLinkVstsGitPackageVersion>1.0.0-beta2-18618-05</MicrosoftSourceLinkVstsGitPackageVersion>

eng/tools/BaselineGenerator/BaselineGenerator.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>netcoreapp2.1</TargetFramework>
6-
<StartArguments>-o "$(MSBuildThisFileDirectory)../../Baseline.Designer.props" --v3 -s https://dotnetfeed.blob.core.windows.net/dotnet-core/flatcontainer</StartArguments>
6+
<StartArguments>-s https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json</StartArguments>
77
<StartWorkingDirectory>$(MSBuildThisFileDirectory)../../</StartWorkingDirectory>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="NuGet.Packaging" Version="4.8.0" />
11+
<PackageReference Include="NuGet.Protocol" Version="4.8.2" />
1212
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.0" />
1313
</ItemGroup>
1414

eng/tools/BaselineGenerator/Program.cs

Lines changed: 220 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33

44
using System;
55
using System.IO;
6+
using System.Linq;
67
using System.Net.Http;
78
using System.Text;
9+
using System.Threading;
810
using System.Threading.Tasks;
911
using System.Xml;
1012
using System.Xml.Linq;
1113
using Microsoft.Extensions.CommandLineUtils;
14+
using NuGet.Common;
15+
using NuGet.Configuration;
1216
using NuGet.Packaging;
13-
using NuGet.Packaging.Core;
17+
using NuGet.Protocol;
18+
using NuGet.Protocol.Core.Types;
19+
using NuGet.Versioning;
1420

1521
namespace PackageBaselineGenerator
1622
{
@@ -26,36 +32,57 @@ static void Main(string[] args)
2632

2733
private readonly CommandOption _source;
2834
private readonly CommandOption _output;
29-
private readonly CommandOption _feedv3;
35+
private readonly CommandOption _update;
3036

3137
public Program()
3238
{
33-
_source = Option("-s|--source <SOURCE>", "The NuGet v2 source of the package to fetch", CommandOptionType.SingleValue);
39+
_source = Option("-s|--package-source <SOURCE>", "The NuGet source of packages to fetch", CommandOptionType.SingleValue);
3440
_output = Option("-o|--output <OUT>", "The generated file output path", CommandOptionType.SingleValue);
35-
_feedv3 = Option("--v3", "Sources is nuget v3", CommandOptionType.NoValue);
41+
_update = Option("-u|--update", "Regenerate the input (Baseline.xml) file.", CommandOptionType.NoValue);
3642

3743
Invoke = () => Run().GetAwaiter().GetResult();
3844
}
3945

4046
private async Task<int> Run()
4147
{
4248
var source = _source.HasValue()
43-
? _source.Value()
44-
: "https://www.nuget.org/api/v2/package";
45-
46-
var packageCache = Environment.GetEnvironmentVariable("NUGET_PACKAGES") != null
47-
? Environment.GetEnvironmentVariable("NUGET_PACKAGES")
48-
: Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages");
49+
? _source.Value().TrimEnd('/')
50+
: "https://api.nuget.org/v3/index.json";
51+
if (_output.HasValue() && _update.HasValue())
52+
{
53+
await Error.WriteLineAsync("'--output' and '--update' options must not be used together.");
54+
return 1;
55+
}
4956

50-
var tempDir = Path.Combine(Directory.GetCurrentDirectory(), "obj", "tmp");
51-
Directory.CreateDirectory(tempDir);
57+
var inputPath = Path.Combine(Directory.GetCurrentDirectory(), "Baseline.xml");
58+
var input = XDocument.Load(inputPath);
59+
var packageSource = new PackageSource(source);
60+
var providers = Repository.Provider.GetCoreV3(); // Get v2 and v3 API support
61+
var sourceRepository = new SourceRepository(packageSource, providers);
62+
if (_update.HasValue())
63+
{
64+
return await RunUpdateAsync(inputPath, input, sourceRepository);
65+
}
5266

53-
var input = XDocument.Load(Path.Combine(Directory.GetCurrentDirectory(), "Baseline.xml"));
67+
var feedType = await sourceRepository.GetFeedType(CancellationToken.None);
68+
var feedV3 = feedType == FeedType.HttpV3;
69+
var packageBase = source + "/package";
70+
if (feedV3)
71+
{
72+
var resources = await sourceRepository.GetResourceAsync<ServiceIndexResourceV3>();
73+
packageBase = resources.GetServiceEntryUri(ServiceTypes.PackageBaseAddress).ToString().TrimEnd('/');
74+
}
5475

5576
var output = _output.HasValue()
5677
? _output.Value()
5778
: Path.Combine(Directory.GetCurrentDirectory(), "Baseline.Designer.props");
5879

80+
var packageCache = Environment.GetEnvironmentVariable("NUGET_PACKAGES") ??
81+
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages");
82+
83+
var tempDir = Path.Combine(Directory.GetCurrentDirectory(), "obj", "tmp");
84+
Directory.CreateDirectory(tempDir);
85+
5986
var baselineVersion = input.Root.Attribute("Version").Value;
6087

6188
var doc = new XDocument(
@@ -66,7 +93,6 @@ private async Task<int> Run()
6693
new XElement("AspNetCoreBaselineVersion", baselineVersion))));
6794

6895
var client = new HttpClient();
69-
7096
foreach (var pkg in input.Root.Descendants("Package"))
7197
{
7298
var id = pkg.Attribute("Id").Value;
@@ -80,25 +106,26 @@ private async Task<int> Run()
80106

81107
if (!File.Exists(nupkgPath))
82108
{
83-
var url = _feedv3.HasValue()
84-
? $"{source}/{id.ToLowerInvariant()}/{version}/{id.ToLowerInvariant()}.{version}.nupkg"
85-
: $"{source}/{id}/{version}";
86-
Console.WriteLine($"Downloading {url}");
87-
88-
var response = await client.GetStreamAsync(url);
109+
var url = feedV3 ?
110+
$"{packageBase}/{id.ToLowerInvariant()}/{version}/{id.ToLowerInvariant()}.{version}.nupkg" :
111+
$"{packageBase}/{id}/{version}";
89112

90-
using (var file = File.Create(nupkgPath))
113+
Console.WriteLine($"Downloading {url}");
114+
using (var response = await client.GetStreamAsync(url))
91115
{
92-
await response.CopyToAsync(file);
116+
using (var file = File.Create(nupkgPath))
117+
{
118+
await response.CopyToAsync(file);
119+
}
93120
}
94121
}
95122

96-
97123
using (var reader = new PackageArchiveReader(nupkgPath))
98124
{
99125
doc.Root.Add(new XComment($" Package: {id}"));
100126

101-
var propertyGroup = new XElement("PropertyGroup",
127+
var propertyGroup = new XElement(
128+
"PropertyGroup",
102129
new XAttribute("Condition", $" '$(PackageId)' == '{id}' "),
103130
new XElement("BaselinePackageVersion", version));
104131
doc.Root.Add(propertyGroup);
@@ -122,12 +149,181 @@ private async Task<int> Run()
122149
Encoding = Encoding.UTF8,
123150
Indent = true,
124151
};
152+
125153
using (var writer = XmlWriter.Create(output, settings))
126154
{
127155
doc.Save(writer);
128156
}
157+
129158
Console.WriteLine($"Generated file in {output}");
159+
130160
return 0;
131161
}
162+
163+
private async Task<int> RunUpdateAsync(
164+
string documentPath,
165+
XDocument document,
166+
SourceRepository sourceRepository)
167+
{
168+
var packageMetadataResource = await sourceRepository.GetResourceAsync<PackageMetadataResource>();
169+
var logger = new Logger(Error, Out);
170+
var hasChanged = false;
171+
using (var cacheContext = new SourceCacheContext { NoCache = true })
172+
{
173+
var versionAttribute = document.Root.Attribute("Version");
174+
hasChanged = await TryUpdateVersionAsync(
175+
versionAttribute,
176+
"Microsoft.AspNetCore.App",
177+
packageMetadataResource,
178+
logger,
179+
cacheContext);
180+
181+
foreach (var package in document.Root.Descendants("Package"))
182+
{
183+
var id = package.Attribute("Id").Value;
184+
versionAttribute = package.Attribute("Version");
185+
var attributeChanged = await TryUpdateVersionAsync(
186+
versionAttribute,
187+
id,
188+
packageMetadataResource,
189+
logger,
190+
cacheContext);
191+
192+
hasChanged |= attributeChanged;
193+
}
194+
}
195+
196+
if (hasChanged)
197+
{
198+
await Out.WriteLineAsync($"Updating {documentPath}.");
199+
200+
var settings = new XmlWriterSettings
201+
{
202+
Async = true,
203+
CheckCharacters = true,
204+
CloseOutput = false,
205+
Encoding = Encoding.UTF8,
206+
Indent = true,
207+
IndentChars = " ",
208+
NewLineOnAttributes = false,
209+
OmitXmlDeclaration = true,
210+
WriteEndDocumentOnClose = true,
211+
};
212+
213+
using (var stream = File.OpenWrite(documentPath))
214+
{
215+
using (var writer = XmlWriter.Create(stream, settings))
216+
{
217+
await document.SaveAsync(writer, CancellationToken.None);
218+
}
219+
}
220+
}
221+
else
222+
{
223+
await Out.WriteLineAsync("No new versions found");
224+
}
225+
226+
return 0;
227+
}
228+
229+
private static async Task<bool> TryUpdateVersionAsync(
230+
XAttribute versionAttribute,
231+
string packageId,
232+
PackageMetadataResource packageMetadataResource,
233+
ILogger logger,
234+
SourceCacheContext cacheContext)
235+
{
236+
var searchMetadata = await packageMetadataResource.GetMetadataAsync(
237+
packageId,
238+
includePrerelease: false,
239+
includeUnlisted: true, // Microsoft.AspNetCore.DataOrotection.Redis package is not listed.
240+
sourceCacheContext: cacheContext,
241+
log: logger,
242+
token: CancellationToken.None);
243+
244+
var currentVersion = NuGetVersion.Parse(versionAttribute.Value);
245+
var versionRange = new VersionRange(
246+
currentVersion,
247+
new FloatRange(NuGetVersionFloatBehavior.Patch, currentVersion));
248+
249+
var latestVersion = versionRange.FindBestMatch(
250+
searchMetadata.Select(metadata => metadata.Identity.Version));
251+
252+
if (latestVersion == null)
253+
{
254+
logger.LogWarning($"Unable to find latest version of '{packageId}'.");
255+
return false;
256+
}
257+
258+
var hasChanged = false;
259+
if (latestVersion != currentVersion)
260+
{
261+
hasChanged = true;
262+
versionAttribute.Value = latestVersion.ToNormalizedString();
263+
}
264+
265+
return hasChanged;
266+
}
267+
268+
private class Logger : ILogger
269+
{
270+
private readonly TextWriter _error;
271+
private readonly TextWriter _out;
272+
273+
public Logger(TextWriter error, TextWriter @out)
274+
{
275+
_error = error;
276+
_out = @out;
277+
}
278+
279+
public void Log(LogLevel level, string data)
280+
{
281+
switch (level)
282+
{
283+
case LogLevel.Debug:
284+
LogDebug(data);
285+
break;
286+
case LogLevel.Error:
287+
LogError(data);
288+
break;
289+
case LogLevel.Information:
290+
LogInformation(data);
291+
break;
292+
case LogLevel.Minimal:
293+
LogMinimal(data);
294+
break;
295+
case LogLevel.Verbose:
296+
LogVerbose(data);
297+
break;
298+
case LogLevel.Warning:
299+
LogWarning(data);
300+
break;
301+
}
302+
}
303+
304+
public void Log(ILogMessage message) => Log(message.Level, message.Message);
305+
306+
public Task LogAsync(LogLevel level, string data)
307+
{
308+
Log(level, data);
309+
return Task.CompletedTask;
310+
}
311+
312+
public Task LogAsync(ILogMessage message) => LogAsync(message.Level, message.Message);
313+
314+
public void LogDebug(string data) => _out.WriteLine($"Debug: {data}");
315+
316+
public void LogError(string data) => _error.WriteLine($"Error: {data}");
317+
318+
public void LogInformation(string data) => _out.WriteLine($"Information: {data}");
319+
320+
public void LogInformationSummary(string data) => _out.WriteLine($"Summary: {data}");
321+
322+
public void LogMinimal(string data) => _out.WriteLine($"Minimal: {data}");
323+
324+
public void LogVerbose(string data) => _out.WriteLine($"Verbose: {data}");
325+
326+
public void LogWarning(string data) => _out.WriteLine($"Warning: {data}");
327+
}
132328
}
133329
}

eng/tools/BaselineGenerator/README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
BaselineGenerator
2-
=================
1+
# BaselineGenerator
32

43
This tool is used to generate an MSBuild file which sets the "baseline" against which servicing updates are built.
54

65
## Usage
76

8-
1. Add to the [Baseline.xml](/eng/Baseline.xml) a list of package ID's and their latest released versions. The source of this information can typically
9-
be found in the build.xml file generated during ProdCon builds. See https://github.com/dotnet/versions/blob/master/build-info/dotnet/product/cli/release/2.1.6/build.xml for example.
7+
Add `--package-source {source}` to the commands below if the packages of interest are not all hosted on NuGet.org.
8+
9+
### Auto-update
10+
11+
1. Run `dotnet run --update` in this project folder.
12+
2. Run `dotnet run` in this project.
13+
14+
### Manual update
15+
16+
1. Add to the [Baseline.xml](/eng/Baseline.xml) a list of package ID's and their latest released versions. The source of
17+
this information can typically be found in the build.xml file generated during ProdCon builds. See
18+
<file://vsufile/patches/sign/NET/CORE_BUILDS/3.0.X/3.0.0/preview5/3.0.100-preview5-011568/manifest.txt> for example.
19+
Update the version at the top of baseline.xml to match prior release (even if no packages changed in the prior release).
1020
2. Run `dotnet run` on this project.

0 commit comments

Comments
 (0)