Move PinVersions into RepoTasks (#535)
This commit is contained in:
parent
469195950e
commit
ca7f72e3f0
27
Universe.sln
27
Universe.sln
|
|
@ -1,27 +0,0 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Visual Studio 15
|
|
||||||
VisualStudioVersion = 15.0.26228.0
|
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PinVersions", "tools\PinVersions\PinVersions.csproj", "{DACA9DFB-508E-45EA-A5CF-C0F5C2BA181B}"
|
|
||||||
EndProject
|
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{085280EC-7055-426A-BF9C-1B692B9599AB}"
|
|
||||||
ProjectSection(SolutionItems) = preProject
|
|
||||||
tools\shared\DependencyGraphSpecProvider.cs = tools\shared\DependencyGraphSpecProvider.cs
|
|
||||||
EndProjectSection
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Any CPU = Debug|Any CPU
|
|
||||||
Release|Any CPU = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{DACA9DFB-508E-45EA-A5CF-C0F5C2BA181B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{DACA9DFB-508E-45EA-A5CF-C0F5C2BA181B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{DACA9DFB-508E-45EA-A5CF-C0F5C2BA181B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{DACA9DFB-508E-45EA-A5CF-C0F5C2BA181B}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
BuildInParallel="$(BatchBuilds)"
|
BuildInParallel="$(BatchBuilds)"
|
||||||
StopOnFirstFailure="true"
|
StopOnFirstFailure="true"
|
||||||
Targets="_BuildRepository"
|
Targets="_BuildRepository"
|
||||||
Properties="BuildGroup=%(BatchedRepository.BuildGroup)" />
|
Properties="BuildGroup=%(BatchedRepository.BuildGroup);BuildNumber=$(BuildNumber)" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<Target Name="_BuildRepository" DependsOnTargets="_PinVersions">
|
<Target Name="_BuildRepository" DependsOnTargets="_PinVersions">
|
||||||
|
|
@ -78,14 +78,16 @@
|
||||||
<Message Text="============ Done building $(RepositoryToBuild) ============" Importance="High" />
|
<Message Text="============ Done building $(RepositoryToBuild) ============" Importance="High" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<Target Name="_PinVersions" DependsOnTargets="_FindDotNetPath">
|
<Target Name="_PinVersions">
|
||||||
|
<ItemGroup>
|
||||||
|
<PinPackageSources Include="$(BuildDir)" />
|
||||||
|
<PinPackageSources Include="$(_DependencyPackagesDirectory)" Condition="Exists('$(_DependencyPackagesDirectory)')" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<RepoTasks.PinVersions
|
||||||
<PinToolBinary>$(RepositoryRoot)tools\PinVersions\bin\$(Configuration)\netcoreapp1.1\PinVersions.dll</PinToolBinary>
|
GraphSpecsRoot="$(_RestoreGraphSpecsDirectory)"
|
||||||
<PinVersionArgs>$(DotNetPath) $(PinToolBinary) --graph-specs-root "$(_RestoreGraphSpecsDirectory) " -s "$(BuildDir) " "$(BuildRepositoryRoot) "</PinVersionArgs>
|
BuildRepositoryRoot="$(BuildRepositoryRoot)"
|
||||||
<PinVersionArgs Condition="Exists('$(_DependencyPackagesDirectory)')">$(PinVersionArgs) -s "$(_DependencyPackagesDirectory) "</PinVersionArgs>
|
PackageSources="@(PinPackageSources)" />
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<Exec Command="$(PinVersionArgs)" />
|
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<!-- This repo does not have solutions to build -->
|
||||||
|
<DisableDefaultTargets>true</DisableDefaultTargets>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
|
|
@ -214,9 +214,4 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<Target Name="_FindDotNetPath">
|
|
||||||
<GetDotNetHost>
|
|
||||||
<Output TaskParameter="ExecutablePath" PropertyName="DotNetPath" />
|
|
||||||
</GetDotNetHost>
|
|
||||||
</Target>
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.Build.Framework;
|
||||||
|
using RepoTasks.VersionPinning;
|
||||||
|
|
||||||
|
namespace RepoTasks
|
||||||
|
{
|
||||||
|
public class PinVersions : Microsoft.Build.Utilities.Task
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public string BuildRepositoryRoot { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public ITaskItem[] PackageSources { get; set; }
|
||||||
|
|
||||||
|
public string GraphSpecsRoot { get; set; }
|
||||||
|
|
||||||
|
public override bool Execute()
|
||||||
|
{
|
||||||
|
if (PackageSources?.Length == 0)
|
||||||
|
{
|
||||||
|
Log.LogError($"Missing PackageSources. At least one item source must be specified.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var graphSpecProvider = !string.IsNullOrEmpty(GraphSpecsRoot)
|
||||||
|
? new DependencyGraphSpecProvider(GraphSpecsRoot)
|
||||||
|
: DependencyGraphSpecProvider.Default;
|
||||||
|
|
||||||
|
using (graphSpecProvider)
|
||||||
|
{
|
||||||
|
var pinVersionUtility = new PinVersionUtility(
|
||||||
|
BuildRepositoryRoot,
|
||||||
|
PackageSources.Select(i => i.ItemSpec).ToList(),
|
||||||
|
graphSpecProvider,
|
||||||
|
Log);
|
||||||
|
pinVersionUtility.Execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="NuGet.ProjectModel" Version="4.0.0" />
|
<PackageReference Include="NuGet.ProjectModel" Version="$(NuGetInMSBuildVersion)" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Import Project="$(RepoTasksSdkPath)\Sdk.targets" Condition="'$(RepoTasksSdkPath)' != '' "/>
|
<Import Project="$(RepoTasksSdkPath)\Sdk.targets" Condition="'$(RepoTasksSdkPath)' != '' "/>
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,5 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<UsingTask TaskName="RepoTasks.CalculateBuildGraph" AssemblyFile="$(_RepoTaskAssembly)" />
|
<UsingTask TaskName="RepoTasks.CalculateBuildGraph" AssemblyFile="$(_RepoTaskAssembly)" />
|
||||||
|
<UsingTask TaskName="RepoTasks.PinVersions" AssemblyFile="$(_RepoTaskAssembly)" />
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -1,17 +1,19 @@
|
||||||
using System;
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
|
||||||
using NuGet.ProjectModel;
|
using NuGet.ProjectModel;
|
||||||
|
|
||||||
namespace UniverseTools
|
namespace RepoTasks.VersionPinning
|
||||||
{
|
{
|
||||||
public class DependencyGraphSpecProvider : IDisposable
|
public class DependencyGraphSpecProvider : IDisposable
|
||||||
{
|
{
|
||||||
private readonly string _packageSpecDirectory;
|
private readonly string _packageSpecDirectory;
|
||||||
private readonly bool _deleteSpecDirectoryOnDispose;
|
private readonly bool _deleteSpecDirectoryOnDispose;
|
||||||
private readonly string _muxerPath;
|
private readonly string _dotnetPath;
|
||||||
|
|
||||||
public DependencyGraphSpecProvider(string packageSpecDirectory)
|
public DependencyGraphSpecProvider(string packageSpecDirectory)
|
||||||
: this(packageSpecDirectory, deleteSpecDirectoryOnDispose: false)
|
: this(packageSpecDirectory, deleteSpecDirectoryOnDispose: false)
|
||||||
|
|
@ -22,7 +24,7 @@ namespace UniverseTools
|
||||||
{
|
{
|
||||||
_packageSpecDirectory = packageSpecDirectory;
|
_packageSpecDirectory = packageSpecDirectory;
|
||||||
_deleteSpecDirectoryOnDispose = deleteSpecDirectoryOnDispose;
|
_deleteSpecDirectoryOnDispose = deleteSpecDirectoryOnDispose;
|
||||||
_muxerPath = new Muxer().MuxerPath;
|
_dotnetPath = Process.GetCurrentProcess().MainModule.FileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DependencyGraphSpecProvider Default { get; } =
|
public static DependencyGraphSpecProvider Default { get; } =
|
||||||
|
|
@ -42,7 +44,7 @@ namespace UniverseTools
|
||||||
|
|
||||||
private void RunMSBuild(string solutionPath, string outputFile)
|
private void RunMSBuild(string solutionPath, string outputFile)
|
||||||
{
|
{
|
||||||
var psi = new ProcessStartInfo(_muxerPath);
|
var psi = new ProcessStartInfo(_dotnetPath);
|
||||||
|
|
||||||
var arguments = new List<string>
|
var arguments = new List<string>
|
||||||
{
|
{
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
using System;
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
@ -6,6 +9,8 @@ using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
using Microsoft.Build.Framework;
|
||||||
|
using Microsoft.Build.Utilities;
|
||||||
using NuGet.Common;
|
using NuGet.Common;
|
||||||
using NuGet.Frameworks;
|
using NuGet.Frameworks;
|
||||||
using NuGet.LibraryModel;
|
using NuGet.LibraryModel;
|
||||||
|
|
@ -13,19 +18,23 @@ using NuGet.ProjectModel;
|
||||||
using NuGet.Protocol;
|
using NuGet.Protocol;
|
||||||
using NuGet.Protocol.Core.Types;
|
using NuGet.Protocol.Core.Types;
|
||||||
using NuGet.Versioning;
|
using NuGet.Versioning;
|
||||||
using UniverseTools;
|
|
||||||
|
|
||||||
namespace PinVersions
|
namespace RepoTasks.VersionPinning
|
||||||
{
|
{
|
||||||
class PinVersionUtility
|
internal class PinVersionUtility
|
||||||
{
|
{
|
||||||
private readonly string _repositoryRoot;
|
private readonly string _repositoryRoot;
|
||||||
private readonly FindPackageByIdResource[] _findPackageResources;
|
private readonly FindPackageByIdResource[] _findPackageResources;
|
||||||
private readonly ConcurrentDictionary<string, Task<NuGetVersion>> _exactMatches = new ConcurrentDictionary<string, Task<NuGetVersion>>(StringComparer.OrdinalIgnoreCase);
|
private readonly ConcurrentDictionary<string, Task<NuGetVersion>> _exactMatches = new ConcurrentDictionary<string, Task<NuGetVersion>>(StringComparer.OrdinalIgnoreCase);
|
||||||
private readonly DependencyGraphSpecProvider _provider;
|
private readonly DependencyGraphSpecProvider _provider;
|
||||||
private readonly SourceCacheContext _sourceCacheContext;
|
private readonly SourceCacheContext _sourceCacheContext;
|
||||||
|
private readonly TaskLoggingHelper _logger;
|
||||||
|
|
||||||
public PinVersionUtility(string repositoryRoot, List<string> pinSources, DependencyGraphSpecProvider provider)
|
public PinVersionUtility(
|
||||||
|
string repositoryRoot,
|
||||||
|
List<string> pinSources,
|
||||||
|
DependencyGraphSpecProvider provider,
|
||||||
|
TaskLoggingHelper logger)
|
||||||
{
|
{
|
||||||
_repositoryRoot = repositoryRoot;
|
_repositoryRoot = repositoryRoot;
|
||||||
_findPackageResources = new FindPackageByIdResource[pinSources.Count];
|
_findPackageResources = new FindPackageByIdResource[pinSources.Count];
|
||||||
|
|
@ -36,14 +45,17 @@ namespace PinVersions
|
||||||
}
|
}
|
||||||
_provider = provider;
|
_provider = provider;
|
||||||
_sourceCacheContext = new SourceCacheContext();
|
_sourceCacheContext = new SourceCacheContext();
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Execute()
|
public void Execute()
|
||||||
{
|
{
|
||||||
|
_logger.LogMessage(MessageImportance.High, $"Pinning package references for projects in {_repositoryRoot}");
|
||||||
|
|
||||||
var solutionPinMetadata = GetProjectPinVersionMetadata();
|
var solutionPinMetadata = GetProjectPinVersionMetadata();
|
||||||
foreach (var cliToolReference in solutionPinMetadata.CLIToolReferences)
|
foreach (var cliToolReference in solutionPinMetadata.CLIToolReferences)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Pinning CLI Tool {cliToolReference.Item1.Name}({cliToolReference.Item1.VersionRange} to {cliToolReference.Item2} for all projects in {_repositoryRoot}.");
|
_logger.LogMessage(MessageImportance.Normal, $"Pinning CLI Tool {cliToolReference.Item1.Name}({cliToolReference.Item1.VersionRange} to {cliToolReference.Item2} for all projects in {_repositoryRoot}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var item in solutionPinMetadata.PinVersionLookup)
|
foreach (var item in solutionPinMetadata.PinVersionLookup)
|
||||||
|
|
@ -53,7 +65,7 @@ namespace PinVersions
|
||||||
|
|
||||||
if (!(projectPinMetadata.Packages.Any() || solutionPinMetadata.CLIToolReferences.Any()))
|
if (!(projectPinMetadata.Packages.Any() || solutionPinMetadata.CLIToolReferences.Any()))
|
||||||
{
|
{
|
||||||
Console.WriteLine($"No package or tool references to pin for {specProject.FilePath}.");
|
_logger.LogMessage(MessageImportance.Normal, $"No package or tool references to pin for {specProject.FilePath}.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,14 +78,14 @@ namespace PinVersions
|
||||||
|
|
||||||
if (projectPinMetadata.Packages.Any())
|
if (projectPinMetadata.Packages.Any())
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Pinning package versions for {specProject.FilePath}.");
|
_logger.LogMessage(MessageImportance.Normal, $"Pinning package versions for {specProject.FilePath}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var pinnedReferences = new XElement("ItemGroup");
|
var pinnedReferences = new XElement("ItemGroup");
|
||||||
foreach (var packageReference in projectPinMetadata.Packages)
|
foreach (var packageReference in projectPinMetadata.Packages)
|
||||||
{
|
{
|
||||||
(var tfm, var libraryRange, var exactVersion) = packageReference;
|
(var tfm, var libraryRange, var exactVersion) = packageReference;
|
||||||
Console.WriteLine($"Pinning reference {libraryRange.Name}({libraryRange.VersionRange} to {exactVersion}.");
|
_logger.LogMessage(MessageImportance.Normal, $"Pinning reference {libraryRange.Name}({libraryRange.VersionRange} to {exactVersion}.");
|
||||||
var metadata = new List<XAttribute>
|
var metadata = new List<XAttribute>
|
||||||
{
|
{
|
||||||
new XAttribute("Update", libraryRange.Name),
|
new XAttribute("Update", libraryRange.Name),
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<TargetFramework>netcoreapp1.1</TargetFramework>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="..\shared\*.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.DotNet.Cli.Utils" Version="1.0.1" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.0" />
|
|
||||||
<PackageReference Include="System.ValueTuple" Version="4.3.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
using System;
|
|
||||||
using Microsoft.Extensions.CommandLineUtils;
|
|
||||||
using UniverseTools;
|
|
||||||
|
|
||||||
namespace PinVersions
|
|
||||||
{
|
|
||||||
class Program
|
|
||||||
{
|
|
||||||
static int Main(string[] args)
|
|
||||||
{
|
|
||||||
var app = new CommandLineApplication();
|
|
||||||
|
|
||||||
var pinSourceOption = app.Option("-s|--source",
|
|
||||||
"Feed containing packages to pin.",
|
|
||||||
CommandOptionType.MultipleValue);
|
|
||||||
|
|
||||||
var packageSpecsDirectoryOption = app.Option("--graph-specs-root",
|
|
||||||
"Directory containing package specs. (Optional)",
|
|
||||||
CommandOptionType.SingleValue);
|
|
||||||
|
|
||||||
var repositoryArgument = app.Argument("Repository", "Repository directory");
|
|
||||||
|
|
||||||
app.OnExecute(() =>
|
|
||||||
{
|
|
||||||
if (!pinSourceOption.HasValue())
|
|
||||||
{
|
|
||||||
Console.Error.WriteLine($"Option {pinSourceOption.Template} must have a value.");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(repositoryArgument.Value))
|
|
||||||
{
|
|
||||||
Console.Error.WriteLine($"Repository argument must be specified.");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
var graphSpecProvider = packageSpecsDirectoryOption.HasValue() ?
|
|
||||||
new DependencyGraphSpecProvider(packageSpecsDirectoryOption.Value().Trim()) :
|
|
||||||
DependencyGraphSpecProvider.Default;
|
|
||||||
|
|
||||||
using (graphSpecProvider)
|
|
||||||
{
|
|
||||||
var pinVersionUtility = new PinVersionUtility(repositoryArgument.Value.Trim(), pinSourceOption.Values, graphSpecProvider);
|
|
||||||
pinVersionUtility.Execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
return app.Execute(args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue