A special target for testing local nuget builds (#14446)
* BuildToNuGetCache target * Skip more stuff that's not required for quick local testing of apps --------- Co-authored-by: Max Katz <maxkatz6@outlook.com>
This commit is contained in:
@@ -73,6 +73,7 @@
|
||||
"items": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"BuildToNuGetCache",
|
||||
"CiAzureLinux",
|
||||
"CiAzureOSX",
|
||||
"CiAzureWindows",
|
||||
@@ -108,6 +109,7 @@
|
||||
"items": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"BuildToNuGetCache",
|
||||
"CiAzureLinux",
|
||||
"CiAzureOSX",
|
||||
"CiAzureWindows",
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
<!-- Build Avalonia.Build.Tasks first because everything depends on it -->
|
||||
<ProjectReference Include="src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj" />
|
||||
<ProjectReference Include="src/**/*.*proj" />
|
||||
<ProjectReference Include="samples/**/*.*proj" />
|
||||
<ProjectReference Include="tests/**/*.*proj" />
|
||||
<ProjectReference Condition="'$(SkipBuildingSamples)' != 'True'" Include="samples/**/*.*proj" />
|
||||
<ProjectReference Condition="'$(SkipBuildingTests)' != 'True'" Include="tests/**/*.*proj" />
|
||||
<ProjectReference Include="packages/**/*.*proj" />
|
||||
<ProjectReference Remove="**/*.shproj" />
|
||||
<ProjectReference Remove="src/Markup/Avalonia.Markup.Xaml/PortableXaml/**/*.*proj" />
|
||||
@@ -27,6 +27,10 @@
|
||||
<ProjectReference Remove="src/iOS/**/*.*proj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(SkipObscurePlatforms)' == 'True'">
|
||||
<ProjectReference Remove="**/*Tizen/**/*.*proj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.VisualStudio.SlnGen" Version="8.5.17" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
+44
-1
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
@@ -38,9 +39,12 @@ partial class Build : NukeBuild
|
||||
[PackageExecutable("Microsoft.DotNet.GenAPI.Tool", "Microsoft.DotNet.GenAPI.Tool.dll", Framework = "net8.0")]
|
||||
Tool ApiGenTool;
|
||||
|
||||
|
||||
|
||||
protected override void OnBuildInitialized()
|
||||
{
|
||||
Parameters = new BuildParameters(this);
|
||||
Parameters = new BuildParameters(this, ScheduledTargets.Contains(BuildToNuGetCache));
|
||||
|
||||
Information("Building version {0} of Avalonia ({1}) using version {2} of Nuke.",
|
||||
Parameters.Version,
|
||||
Parameters.Configuration,
|
||||
@@ -82,6 +86,12 @@ partial class Build : NukeBuild
|
||||
c.AddProperty("PackageVersion", Parameters.Version)
|
||||
.SetConfiguration(Parameters.Configuration)
|
||||
.SetVerbosity(DotNetVerbosity.Minimal);
|
||||
if (Parameters.IsPackingToLocalCache)
|
||||
c
|
||||
.AddProperty("ForcePackAvaloniaNative", "True")
|
||||
.AddProperty("SkipObscurePlatforms", "True")
|
||||
.AddProperty("SkipBuildingSamples", "True")
|
||||
.AddProperty("SkipBuildingTests", "True");
|
||||
return c;
|
||||
}
|
||||
DotNetBuildSettings ApplySetting(DotNetBuildSettings c, Configure<DotNetBuildSettings> configurator = null) =>
|
||||
@@ -325,6 +335,39 @@ partial class Build : NukeBuild
|
||||
.DependsOn(Package)
|
||||
.DependsOn(ZipFiles);
|
||||
|
||||
Target BuildToNuGetCache => _ => _
|
||||
.DependsOn(CreateNugetPackages)
|
||||
.Executes(() =>
|
||||
{
|
||||
if (!Parameters.IsPackingToLocalCache)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
foreach (var path in Parameters.NugetRoot.GlobFiles("*.nupkg"))
|
||||
{
|
||||
using var f = File.Open(path.ToString(), FileMode.Open, FileAccess.Read);
|
||||
using var zip = new ZipArchive(f, ZipArchiveMode.Read);
|
||||
var nuspecEntry = zip.Entries.First(e => e.FullName.EndsWith(".nuspec") && e.FullName == e.Name);
|
||||
var packageId = XDocument.Load(nuspecEntry.Open()).Document.Root
|
||||
.Elements().First(x => x.Name.LocalName == "metadata")
|
||||
.Elements().First(x => x.Name.LocalName == "id").Value;
|
||||
|
||||
var packagePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
|
||||
".nuget",
|
||||
"packages",
|
||||
packageId.ToLowerInvariant(),
|
||||
BuildParameters.LocalBuildVersion);
|
||||
if (Directory.Exists(packagePath))
|
||||
Directory.Delete(packagePath, true);
|
||||
Directory.CreateDirectory(packagePath);
|
||||
zip.ExtractToDirectory(packagePath);
|
||||
File.WriteAllText(Path.Combine(packagePath, ".nupkg.metadata"), @"{
|
||||
""version"": 2,
|
||||
""contentHash"": ""e900dFK7jHJ2WcprLcgJYQoOMc6ejRTwAAMi0VGOFbSczcF98ZDaqwoQIiyqpAwnja59FSbV+GUUXfc3vaQ2Jg=="",
|
||||
""source"": ""https://api.nuget.org/v3/index.json""
|
||||
}");
|
||||
}
|
||||
});
|
||||
|
||||
Target GenerateCppHeaders => _ => _.Executes(() =>
|
||||
{
|
||||
var file = MicroComCodeGenerator.Parse(
|
||||
|
||||
@@ -53,7 +53,10 @@ public partial class Build
|
||||
public bool IsMyGetRelease { get; }
|
||||
public bool IsNuGetRelease { get; }
|
||||
public bool PublishTestResults { get; }
|
||||
public string Version { get; }
|
||||
public string Version { get; set; }
|
||||
public const string LocalBuildVersion = "9999.0.0-localbuild";
|
||||
public bool IsPackingToLocalCache { get; private set; }
|
||||
|
||||
public AbsolutePath ArtifactsDir { get; }
|
||||
public AbsolutePath NugetIntermediateRoot { get; }
|
||||
public AbsolutePath NugetRoot { get; }
|
||||
@@ -68,7 +71,7 @@ public partial class Build
|
||||
public bool UpdateApiValidationSuppression { get; }
|
||||
public AbsolutePath ApiValidationSuppressionFiles { get; }
|
||||
|
||||
public BuildParameters(Build b)
|
||||
public BuildParameters(Build b, bool isPackingToLocalCache)
|
||||
{
|
||||
// ARGUMENTS
|
||||
Configuration = b.Configuration ?? "Release";
|
||||
@@ -124,6 +127,12 @@ public partial class Build
|
||||
|
||||
PublishTestResults = true;
|
||||
}
|
||||
|
||||
if (isPackingToLocalCache)
|
||||
{
|
||||
IsPackingToLocalCache = true;
|
||||
Version = LocalBuildVersion;
|
||||
}
|
||||
|
||||
// DIRECTORIES
|
||||
ArtifactsDir = RootDirectory / "artifacts";
|
||||
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
dotnet run --project _build.csproj -- --target BuildToNuGetCache --skip CompileHtmlPreviewer Compile Clean
|
||||
@@ -4,6 +4,7 @@
|
||||
<PackAvaloniaNative Condition="'$(PackAvaloniaNative)' == ''">$([MSBuild]::IsOSPlatform(OSX))</PackAvaloniaNative>
|
||||
<IsPackable>$(PackAvaloniaNative)</IsPackable>
|
||||
<IsPackable Condition="'$([MSBuild]::IsOSPlatform(OSX))' == 'True'">true</IsPackable>
|
||||
<IsPackable Condition="'$(ForcePackAvaloniaNative)' == 'True'">True</IsPackable>
|
||||
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
Reference in New Issue
Block a user