Skip to content

Commit

Permalink
Manually backport BaselineGenerator changes from release/2.2 branch
Browse files Browse the repository at this point in the history
- needed to get latest Microsoft.Extensions.Logging.Testing package
  • Loading branch information
dougbu committed Mar 14, 2019
1 parent b3dfaf1 commit 46aa691
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
4 changes: 2 additions & 2 deletions eng/tools/BaselineGenerator/BaselineGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<StartArguments>-o "$(MSBuildThisFileDirectory)../../Baseline.Designer.props"</StartArguments>
<StartWorkingDirectory>$(MSBuildProjectDirectory)/../../</StartWorkingDirectory>
<StartArguments>-o "$(MSBuildThisFileDirectory)../../Baseline.Designer.props" --v3 -s https://dotnetfeed.blob.core.windows.net/dotnet-core/flatcontainer</StartArguments>
<StartWorkingDirectory>$(MSBuildThisFileDirectory)../../</StartWorkingDirectory>
</PropertyGroup>

<ItemGroup>
Expand Down
36 changes: 19 additions & 17 deletions eng/tools/BaselineGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ static void Main(string[] args)

private readonly CommandOption _source;
private readonly CommandOption _output;
private readonly CommandOption _feedv3;

public Program()
{
_source = Option("-s|--source <SOURCE>", "The NuGet v2 source of the package to fetch", CommandOptionType.SingleValue);
_output = Option("-o|--output <OUT>", "The generated file output path", CommandOptionType.SingleValue);
_feedv3 = Option("--v3", "Sources is nuget v3", CommandOptionType.NoValue);

Invoke = () => Run().GetAwaiter().GetResult();
}
Expand All @@ -48,7 +50,7 @@ private async Task<int> Run()
var tempDir = Path.Combine(Directory.GetCurrentDirectory(), "obj", "tmp");
Directory.CreateDirectory(tempDir);

var input = XDocument.Load(Path.Combine(Directory.GetCurrentDirectory(), "baseline.xml"));
var input = XDocument.Load(Path.Combine(Directory.GetCurrentDirectory(), "Baseline.xml"));

var output = _output.HasValue()
? _output.Value()
Expand Down Expand Up @@ -78,32 +80,30 @@ private async Task<int> Run()

if (!File.Exists(nupkgPath))
{
var url = $"{source}/{id}/{version}";
var url = _feedv3.HasValue()
? $"{source}/{id.ToLowerInvariant()}/{version}/{id.ToLowerInvariant()}.{version}.nupkg"
: $"{source}/{id}/{version}";
Console.WriteLine($"Downloading {url}");

var response = await client.GetStreamAsync(url);

using (var file = File.Create(nupkgPath))
{
Console.WriteLine($"Downloading {url}");
var response = await client.GetStreamAsync(url);
await response.CopyToAsync(file);
}
}


using (var reader = new PackageArchiveReader(nupkgPath))
{
var first = true;
foreach (var group in reader.NuspecReader.GetDependencyGroups())
{
if (first)
{
first = false;
doc.Root.Add(new XComment($" Package: {id}"));
doc.Root.Add(new XComment($" Package: {id}"));

var propertyGroup = new XElement("PropertyGroup",
new XAttribute("Condition", $" '$(PackageId)' == '{id}' "),
new XElement("BaselinePackageVersion", version));
doc.Root.Add(propertyGroup);
}
var propertyGroup = new XElement("PropertyGroup",
new XAttribute("Condition", $" '$(PackageId)' == '{id}' "),
new XElement("BaselinePackageVersion", version));
doc.Root.Add(propertyGroup);

foreach (var group in reader.NuspecReader.GetDependencyGroups())
{
var itemGroup = new XElement("ItemGroup", new XAttribute("Condition", $" '$(PackageId)' == '{id}' AND '$(TargetFramework)' == '{group.TargetFramework.GetShortFolderName()}' "));
doc.Root.Add(itemGroup);

Expand All @@ -126,6 +126,8 @@ private async Task<int> Run()
doc.Save(writer);
}

Console.WriteLine($"Generated file in {output}");

return 0;
}
}
Expand Down
3 changes: 2 additions & 1 deletion eng/tools/BaselineGenerator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This tool is used to generate an MSBuild file which sets the "baseline" against

## Usage

1. Add to the [baseline.xml](./baseline.xml) a list of package ID's and their latest released versions. The source of this information can typically
1. Add to the [Baseline.xml](../../Baseline.xml) a list of package ID's and their latest released versions. The source of this information can typically
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.
- Update the version at the top of baseline.xml to match prior release (even if no packages changed in the prior release).
2. Run `dotnet run` on this project.

0 comments on commit 46aa691

Please sign in to comment.