Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK ignores GeneratePackageOnBuild #16651

Merged
merged 7 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions build/test-scripts/run-netcore-mobile-template-tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ $projects =
@("5.2/uno52Lib/uno52Lib.csproj", @("-f", "net8.0-maccatalyst"), $true, $true),
@("5.2/uno52Lib/uno52Lib.csproj", @("-f", "net8.0-desktop"), $true, $true),

#
# 5.2 Uno NuGet Lib
#
@("5.2/uno52Lib/uno52Lib.csproj", @(), $true, $true),

# Default mode for the template is WindowsAppSDKSelfContained=true, which requires specifying a target platform.
@("5.2/uno52Lib/uno52Lib.csproj", @("-p:Platform=x86" , "-p:TargetFramework=net8.0-windows10.0.19041"), $false, $true),

Expand Down
5 changes: 5 additions & 0 deletions src/SolutionTemplate/5.1/uno51blank/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
<Project>
<Target Name="ValidateIsPackable"
AfterTargets="CoreCompile;Build">
<Error Text="Expected IsPackable='false', however it actually equals '$(IsPackable)'."
Condition="$(IsPackable) == 'true'" />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
<Project>
<Target Name="ValidateIsPackable"
AfterTargets="CoreCompile;Build">
<Error Text="Expected IsPackable='false', however it actually equals '$(IsPackable)'."
Condition="$(IsPackable) == 'true'" />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
<Project>
<Target Name="ValidateIsPackable"
AfterTargets="CoreCompile;Build">
<Error Text="Expected IsPackable='false', however it actually equals '$(IsPackable)'."
Condition="$(IsPackable) == 'true'" />
</Target>
</Project>
5 changes: 5 additions & 0 deletions src/SolutionTemplate/5.2/uno52Lib/uno52Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@
<!-- <FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" RuntimeFrameworkVersion="10.0.22621.28" />
<FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" TargetingPackVersion="10.0.22621.28" /> -->
</ItemGroup>
<Target Name="ValidateIsPackable"
AfterTargets="CoreCompile;Build">
<Error Text="Expected IsPackable='false', however it actually equals '$(IsPackable)'."
Condition="$(IsPackable) == 'true'" />
</Target>
</Project>
6 changes: 6 additions & 0 deletions src/SolutionTemplate/5.2/uno52NuGetLib/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace uno52Lib;

public class Class1
{
}

5 changes: 5 additions & 0 deletions src/SolutionTemplate/5.2/uno52NuGetLib/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"msbuild-sdks": {
"Uno.Sdk": "5.2.0-dev.2002"
}
}
108 changes: 108 additions & 0 deletions src/SolutionTemplate/5.2/uno52NuGetLib/uno52NuGetLib.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<Project Sdk="Uno.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net8.0-ios;net8.0-maccatalyst;net8.0-windows10.0.19041;net8.0-browserwasm;net8.0-desktop</TargetFrameworks>

<!-- Disabled for https://github.com/unoplatform/uno.check/issues/241 -->
<TargetFrameworks Condition="!$([MSBuild]::IsOSPlatform('linux'))">$(TargetFrameworks);net8.0-android</TargetFrameworks>

<!-- Ensures the .xr.xml files are generated in a proper layout folder -->
<GenerateLibraryLayout>true</GenerateLibraryLayout>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UnoSdkDebugging>true</UnoSdkDebugging>
<OutputType>Library</OutputType>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
<!--
If you encounter this error message:

error NETSDK1148: A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll.
Please update to a newer .NET SDK in order to reference this assembly.

This means that the two packages below must be aligned with the "build" version number of
the "Microsoft.Windows.SDK.BuildTools" package above, and the "revision" version number
must be the highest found in https://www.nuget.org/packages/Microsoft.Windows.SDK.NET.Ref.
-->
<!-- <FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" RuntimeFrameworkVersion="10.0.22621.28" />
<FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" TargetingPackVersion="10.0.22621.28" /> -->
</ItemGroup>
<Target Name="ValidateIsPackable"
AfterTargets="CoreCompile;Build">
<Error Text="Expected IsPackable='true', however it actually equals '$(IsPackable)'."
Condition="$(IsPackable) != 'true'" />
</Target>

<Target Name="ValidatePackageDependencies"
AfterTargets="GenerateNuspec">
<ItemGroup>
<ExpectedReference Include="Uno.WinUI" />
<ExpectedReference Include="Microsoft.WindowsAppSDK" />
<ExpectedReference Include="Microsoft.Windows.SDK.BuildTools" />
<ExpectedMissingReference Include="Uno.Resizetizer" />
<ExpectedMissingReference Include="Uno.Core.Extensions.Logging.Singleton" />
</ItemGroup>

<ValidatePackageReferences
NuGetPackOutputFiles="@(NuGetPackOutput)"
ExpectedReferences="@(ExpectedReference)"
ExpectedMissingReferences="@(ExpectedMissingReference)" />
</Target>

<UsingTask TaskName="ValidatePackageReferences" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<NuGetPackOutputFiles ParameterType="System.String[]" Required="true" />
<ExpectedReferences ParameterType="System.String[]" Required="true" />
<ExpectedMissingReferences ParameterType="System.String[]" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Code Type="Fragment" Language="cs">
<![CDATA[
foreach (var outputFile in NuGetPackOutputFiles)
{
if (Path.GetExtension(outputFile) != ".nuspec" || outputFile.Contains(".symbols."))
{
continue;
}

if (!File.Exists(outputFile))
{
Log.LogError("The nuspec file '{0}' does not exist on the disk.", outputFile);
}

var nuspec = File.ReadAllText(outputFile);
var dependencyStringFormat = "<dependency id=\"{0}\"";

foreach (var expectedReference in ExpectedReferences)
{
if (!nuspec.Contains(string.Format(System.Globalization.CultureInfo.InvariantCulture, dependencyStringFormat, expectedReference)))
{
Log.LogError("Missing expected package dependency: {0}", expectedReference);
}
else
{
Log.LogMessage(MessageImportance.High, "Found package dependency for: {0}.", expectedReference);
}
}

foreach (var expectedMissingReference in ExpectedMissingReferences)
{
if (nuspec.Contains(string.Format(System.Globalization.CultureInfo.InvariantCulture, dependencyStringFormat, expectedMissingReference)))
{
Log.LogError("Found package dependency for: {0}.", expectedMissingReference);
}
else
{
Log.LogMessage(MessageImportance.High, "Confirmed no package dependency for: {0}", expectedMissingReference);
}
}
}
]]>
</Code>
</Task>
</UsingTask>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@
<!-- <FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" RuntimeFrameworkVersion="10.0.22621.28" />
<FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" TargetingPackVersion="10.0.22621.28" /> -->
</ItemGroup>
<Target Name="ValidateIsPackable"
AfterTargets="CoreCompile;Build">
<Error Text="Expected IsPackable='false', however it actually equals '$(IsPackable)'."
Condition="$(IsPackable) == 'true'" />
</Target>
</Project>
5 changes: 5 additions & 0 deletions src/SolutionTemplate/5.2/uno52blank/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
<Project>
<Target Name="ValidateIsPackable"
AfterTargets="CoreCompile;Build">
<Error Text="Expected IsPackable='false', however it actually equals '$(IsPackable)'."
Condition="$(IsPackable) == 'true'" />
</Target>
</Project>
19 changes: 13 additions & 6 deletions src/Uno.Sdk/Models/PackageReference.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
using Microsoft.Build.Framework;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

#nullable enable
namespace Uno.Sdk.Models;

internal record PackageReference(string PackageId, string Version, string? ExcludeAssets = null)
internal record PackageReference(string PackageId, string Version, IDictionary<string, string> MetaData)
{
public ITaskItem ToTaskItem()
{
var taskItem = new TaskItem
{
ItemSpec = PackageId,
};

foreach(var data in MetaData)
jeromelaban marked this conversation as resolved.
Show resolved Hide resolved
{
if (data.Key == "ProjectSystem")

Check failure on line 20 in src/Uno.Sdk/Models/PackageReference.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Uno.Sdk/Models/PackageReference.cs#L20

Add curly braces around the nested statement(s) in this 'if' block.
continue;

taskItem.SetMetadata(data.Key, data.Value);
}

taskItem.SetMetadata(nameof(Version), Version);
taskItem.SetMetadata("IsImplicitlyDefined", bool.TrueString);
taskItem.SetMetadata("Sdk", "Uno");
if (!string.IsNullOrEmpty(ExcludeAssets))
{
taskItem.SetMetadata(nameof(ExcludeAssets), ExcludeAssets);
}
return taskItem;
}
}
3 changes: 0 additions & 3 deletions src/Uno.Sdk/Sdk/Sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ Copyright (C) Uno Platform Inc. All rights reserved.
<_UnoSdkTargetsDirectory>$([MSBuild]::EnsureTrailingSlash($(_UnoSdkTargetsDirectory)))</_UnoSdkTargetsDirectory>
<CustomAfterDirectoryBuildProps>$(CustomAfterDirectoryBuildProps);$(_UnoSdkTargetsDirectory)Uno.Import.SolutionConfig.props</CustomAfterDirectoryBuildProps>
<CustomAfterDirectoryBuildProps>$(CustomAfterDirectoryBuildProps);$(_UnoSdkTargetsDirectory)Uno.IsPlatform.props</CustomAfterDirectoryBuildProps>

<!-- We do this to make sure that we include Resizetizer by default. Libraries using Uno.Sdk should have this set to true -->
<IsPackable Condition=" '$(IsPackable)' == '' ">false</IsPackable>
</PropertyGroup>

<!-- We want to try to avoid having AnyCPU passed-->
Expand Down
11 changes: 5 additions & 6 deletions src/Uno.Sdk/Tasks/ImplicitPackagesResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public sealed class ImplicitPackagesResolver_v0 : Task
[Required]
public string OutputType { get; set; } = null!;

public bool IsPackable { get; set; }

public bool Optimize { get; set; }

[Required]
Expand Down Expand Up @@ -177,8 +175,9 @@ public sealed override bool Execute()
foreach (var reference in ImplicitPackageReferences)
{
var packageId = reference.ItemSpec;
var excludeAssets = packageId == "Uno.WinUI.DevServer" && Optimize ? "all" : null;
AddPackage(packageId, excludeAssets);
var metadata = reference.MetadataNames.Cast<string>()
.ToDictionary(x => x, x => reference.GetMetadata(x));
AddPackage(packageId, metadata);
}
}
catch (Exception ex)
Expand Down Expand Up @@ -350,7 +349,7 @@ private void VerifyFeature(UnoFeature feature, string? version, [CallerArgumentE
}
}

private void AddPackage(string packageId, string? excludeAssets = null)
private void AddPackage(string packageId, IDictionary<string, string> metadata)
{
// 1) Check for Existing References
var existingReference = PackageReferences.SingleOrDefault(x => x.ItemSpec == packageId);
Expand Down Expand Up @@ -399,7 +398,7 @@ private void AddPackage(string packageId, string? excludeAssets = null)

// 5) Add the Implicit Package Reference
Debug("Adding Implicit Reference for '{0}' with version: '{1}'.", packageId, version);
_implicitPackages.Add(new PackageReference(packageId, version, excludeAssets));
_implicitPackages.Add(new PackageReference(packageId, version, metadata));
}

private void Debug(string message, params object[] args)
Expand Down
3 changes: 3 additions & 0 deletions src/Uno.Sdk/targets/Uno.Common.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<Project>

<PropertyGroup>
<!-- We do this to make sure that we include Resizetizer by default. Libraries using Uno.Sdk should have this set to true -->
<IsPackable Condition=" '$(IsPackable)' == '' ">$([MSBuild]::ValueOrDefault('$(GeneratePackageOnBuild)', 'false'))</IsPackable>

<_IsUnoSingleProjectAndLegacy>false</_IsUnoSingleProjectAndLegacy>
<_IsUnoSingleProjectAndLegacy Condition=" $(SingleProject) == 'true' OR $(UnoSingleProject) == 'true' ">true</_IsUnoSingleProjectAndLegacy>

Expand Down
23 changes: 17 additions & 6 deletions src/Uno.Sdk/targets/Uno.Implicit.Packages.ProjectSystem.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,28 @@
-->
<ItemGroup>
<_UnoProjectSystemPackageReference Include="Uno.WinUI" ProjectSystem="true" />
<_UnoProjectSystemPackageReference Include="Uno.Resizetizer" ProjectSystem="true" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Condition="$(_ImplicitRestoreOutputType) == 'Exe'">
<_UnoProjectSystemPackageReference Include="Uno.WinUI.DevServer" ProjectSystem="true" />
<_UnoProjectSystemPackageReference Include="Uno.WinUI.DevServer" ProjectSystem="true" Condition="$(Optimize) != 'true'" />
<_UnoProjectSystemPackageReference Include="Uno.WinUI.DevServer" ProjectSystem="true" Exclude="all" Condition="$(Optimize) == 'true'" />
</ItemGroup>

<ItemGroup Condition="$(IsPackable) != 'true'">
<_UnoProjectSystemPackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" ProjectSystem="true" />
<_UnoProjectSystemPackageReference Include="Uno.Resizetizer" ProjectSystem="true" />
<_UnoProjectSystemPackageReference Include="Microsoft.Extensions.Logging.Console" ProjectSystem="true" />
</ItemGroup>
<Choose>
<When Condition="$(UnoSingleProject) == 'true'">
<ItemGroup Condition="$(IsUnoHead) == 'true'">
<_UnoProjectSystemPackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" ProjectSystem="true" />
<_UnoProjectSystemPackageReference Include="Microsoft.Extensions.Logging.Console" ProjectSystem="true" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup Condition="$(IsPackable) != 'true'">
<_UnoProjectSystemPackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" ProjectSystem="true" />
<_UnoProjectSystemPackageReference Include="Microsoft.Extensions.Logging.Console" ProjectSystem="true" />
</ItemGroup>
</Otherwise>
</Choose>

<ItemGroup Condition="$(UnoFeatures.Contains(';Maps;'))">
<_UnoProjectSystemPackageReference Include="Uno.WinUI.Maps" ProjectSystem="true" />
Expand Down
1 change: 0 additions & 1 deletion src/Uno.Sdk/targets/Uno.Implicit.Packages.targets
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
Optimize="$(Optimize)"
OutputType="$(_ImplicitRestoreOutputType)"
UnoFeatures="$(UnoFeatures)"
IsPackable="$(IsPackable)"
TargetFramework="$(TargetFramework)"
ProjectName="$(MSBuildProjectName)"
ImplicitPackageReferences="@(_UnoProjectSystemPackageReference)"
Expand Down