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

fix: Pack add-ins discovery targets with the dev-server (backport #19464) #19473

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Uno.Sdk/targets/Uno.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@

</Target>

<<<<<<< HEAD
<<<<<<< HEAD
dr1rrb marked this conversation as resolved.
Show resolved Hide resolved
<Target Name="_UnoVSCleanupOtherTFMsForHR"
Condition="
'$(IsImplicitlyTriggeredBuild)' == 'true'
Expand All @@ -165,6 +167,8 @@
</ItemGroup>
</Target>

=======
>>>>>>> f980d05414 (fix: Fix invalid config when using Uno.SDK)
dr1rrb marked this conversation as resolved.
Show resolved Hide resolved
<Target Name="UnoDumpTargetFrameworks">
<!--
This target is used to dump the target frameworks to the output window.
Expand All @@ -179,6 +183,12 @@
Encoding="Unicode"/>
</Target>

<<<<<<< HEAD
=======

>>>>>>> 36a0d9b107 (fix: Pack add-ins discovery tragets with the dev-server to be able to run them no matter the SDK sued by the project)
=======
>>>>>>> f980d05414 (fix: Fix invalid config when using Uno.SDK)
dr1rrb marked this conversation as resolved.
Show resolved Hide resolved
<Import Project="Uno.SingleProject.VS.Build.targets"
Condition=" '$(UnoSingleProject)' == 'true' AND '$(BuildingInsideVisualStudio)' == 'true' " />
</Project>
9 changes: 9 additions & 0 deletions src/Uno.UI.RemoteControl.Host/DevServer.Custom.Targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>
<Target Name="UnoDumpTargetFrameworks">
<Message Text="This is not a Uno.SDK project, no TFM to dump." Importance="High" />
</Target>

<Target Name="UnoDumpRemoteControlAddIns">
<Message Text="This is not a Uno.SDK project, no add-in to dump." Importance="High" />
</Target>
</Project>
12 changes: 10 additions & 2 deletions src/Uno.UI.RemoteControl.Host/Extensibility/AddIns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Microsoft.Extensions.Logging;
using Uno.Extensions;
Expand All @@ -16,9 +17,13 @@ public class AddIns

public static IImmutableList<string> Discover(string solutionFile)
{
// Note: We include the targets "on the fly" so if a project uses Microsoft.NET.Sdk instead of Uno.Sdk, we will still have the targets defined.
var targetsFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "DevServer.Custom.Targets");

var tmp = Path.GetTempFileName();
var wd = Path.GetDirectoryName(solutionFile);
var command = $"build \"{solutionFile}\" -t:UnoDumpTargetFrameworks \"-p:UnoDumpTargetFrameworksTargetFile={tmp}\" --verbosity quiet";
string DumpTFM(string v) => $"build \"{solutionFile}\" -t:UnoDumpTargetFrameworks \"-p:UnoDumpTargetFrameworksTargetFile={tmp}\" \"-p:CustomBeforeMicrosoftCSharpTargets={targetsFile}\" --verbosity {v}";
var command = DumpTFM("quiet");
var result = ProcessHelper.RunProcess("dotnet", command, wd);
var targetFrameworks = Read(tmp);

Expand All @@ -35,7 +40,10 @@ public static IImmutableList<string> Discover(string solutionFile)
}
else
{
result = ProcessHelper.RunProcess("dotnet", DumpTFM("diagnostic"), wd);

_log.Log(LogLevel.Warning, msg);
_log.Log(LogLevel.Debug, result.output);
}
}

Expand All @@ -51,7 +59,7 @@ public static IImmutableList<string> Discover(string solutionFile)
foreach (var targetFramework in targetFrameworks)
{
tmp = Path.GetTempFileName();
command = $"build \"{solutionFile}\" -t:UnoDumpRemoteControlAddIns \"-p:UnoDumpRemoteControlAddInsTargetFile={tmp}\" --verbosity quiet --framework \"{targetFramework}\" -nowarn:MSB4057";
command = $"build \"{solutionFile}\" -t:UnoDumpRemoteControlAddIns \"-p:UnoDumpRemoteControlAddInsTargetFile={tmp}\" \"-p:CustomBeforeMicrosoftCSharpTargets={targetsFile}\" --verbosity quiet --framework \"{targetFramework}\" -nowarn:MSB4057";
result = ProcessHelper.RunProcess("dotnet", command, wd);
if (!string.IsNullOrWhiteSpace(result.error))
{
Expand Down
22 changes: 14 additions & 8 deletions src/Uno.UI.RemoteControl.Host/Uno.UI.RemoteControl.Host.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
</ProjectReference>
</ItemGroup>

<ItemGroup>
<!--
This forces the .net version to use, so the dev server will load the right core assemblies.
Even if we make sure to run the version from the right .net<7|8> directory, if the computer has a newer version of .net than the version used to compiled the target app,
it might use that newer version (even if we have a RollFoward policy).
This works only when the dev-server is started in the .dll file directory! (Which is the case of hot-reload tests helper of the runtime-tests engine).
-->
<ItemGroup>
<!--
This forces the .net version to use, so the dev server will load the right core assemblies.
Even if we make sure to run the version from the right .net<7|8> directory, if the computer has a newer version of .net than the version used to compiled the target app,
it might use that newer version (even if we have a RollFoward policy).
This works only when the dev-server is started in the .dll file directory! (Which is the case of hot-reload tests helper of the runtime-tests engine).
-->
<Content Update="Config\*.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
Expand All @@ -67,7 +67,13 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<TargetPath>global.json</TargetPath>
</Content>
</ItemGroup>
</ItemGroup>

<ItemGroup>
<None Update="DevServer.Custom.Targets">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<Target Name="_UnoToolkitOverrideNuget" AfterTargets="AfterBuild" DependsOnTargets="BuiltProjectOutputGroup" Condition="'$(UnoNugetOverrideVersion)'!=''">
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Extensions.Logging;
using Uno.Extensions;

namespace Uno.UI.RemoteControl.Helpers
{
internal class ProcessHelper
{
private static readonly ILogger _log = typeof(ProcessHelper).Log();

public static (int exitCode, string output, string error) RunProcess(string executable, string parameters, string? workingDirectory = null)
{
if (!OperatingSystem.IsWindows()
Expand All @@ -19,6 +23,11 @@ public static (int exitCode, string output, string error) RunProcess(string exec
executable = Path.GetFileNameWithoutExtension(executable);
}

if (_log.IsEnabled(LogLevel.Trace))
{
_log.LogTrace($"Executing '{executable} {parameters}' in '{workingDirectory ?? Environment.CurrentDirectory}'");
}

var p = new Process
{
StartInfo =
Expand Down
Loading