Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 2131ea1

Browse files
[xamlc] fix duplicate Mono.Cecil search paths (#12030)
I was building the Control Gallery and saw: XamlCTask Compiling Xaml, assembly: obj\Debug\netstandard2.0\Xamarin.Forms.Controls.dll Adding searchpath C:\Users\jopepper\.nuget\packages\netstandard.library\2.0.3\build\netstandard2.0\ref Adding searchpath C:\Users\jopepper\.nuget\packages\netstandard.library\2.0.3\build\netstandard2.0\ref Adding searchpath C:\Users\jopepper\.nuget\packages\netstandard.library\2.0.3\build\netstandard2.0\ref Adding searchpath C:\Users\jopepper\.nuget\packages\newtonsoft.json\12.0.3\lib\netstandard2.0 Adding searchpath C:\Users\jopepper\.nuget\packages\nunit\3.12.0\lib\netstandard2.0 Adding searchpath C:\Users\jopepper\.nuget\packages\xam.plugin.deviceinfo\3.0.2\lib\netstandard1.0 Adding searchpath C:\Users\jopepper\.nuget\packages\xam.plugin.deviceinfo\3.0.2\lib\netstandard1.0 Adding searchpath C:\Users\jopepper\.nuget\packages\netstandard.library\2.0.3\build\netstandard2.0\ref Adding searchpath C:\Users\jopepper\.nuget\packages\netstandard.library\2.0.3\build\netstandard2.0\ref ... 122 lines in total. In f330652 there was an attempt to fix this in the past with a `.Distinct()` call, but `Path.GetDirectoryName()` wasn't called first. After reordering things, the `<XamlCTask/>` now prints 9 search paths for the Control Gallery: XamlCTask Compiling Xaml, assembly: obj\Debug\netstandard2.0\Xamarin.Forms.Controls.dll Adding searchpath C:\Users\jopepper\.nuget\packages\netstandard.library\2.0.3\build\netstandard2.0\ref Adding searchpath C:\Users\jopepper\.nuget\packages\newtonsoft.json\12.0.3\lib\netstandard2.0 Adding searchpath C:\Users\jopepper\.nuget\packages\nunit\3.12.0\lib\netstandard2.0 Adding searchpath C:\Users\jopepper\.nuget\packages\xam.plugin.deviceinfo\3.0.2\lib\netstandard1.0 Adding searchpath C:\src\Xamarin.Forms\Xamarin.Forms.Core\bin\Debug\netstandard2.0 Adding searchpath C:\src\Xamarin.Forms\Xamarin.Forms.CustomAttributes\bin\Debug\netstandard2.0 Adding searchpath C:\src\Xamarin.Forms\Xamarin.Forms.Maps\bin\Debug\netstandard2.0 Adding searchpath C:\src\Xamarin.Forms\Xamarin.Forms.Platform\bin\Debug\netstandard2.0 Adding searchpath C:\src\Xamarin.Forms\Xamarin.Forms.Xaml\bin\Debug\netstandard2.0 Other changes to `<XamlCTask/>`: * Made `ReferencePath` a `string[]` so that MSBuild can split the item groups for us. This way we don't have to call `string.Split()` and weird (and valid!) separators work such as space characters or %3b. * Removed `DependencyPaths`, as I could not find any usage of it. ~~ Results ~~ I could see small performance difference fixing this. On Windows + .NET framework: Before: 2140 ms XamlCTask 1 calls After: 2074 ms XamlCTask 1 calls On macOS + Mono: Before: 7580 ms XamlCTask 1 calls After: 7480 ms XamlCTask 1 calls My PC is newer/faster than my Mac, but I think this probably saves between 65ms-100ms for `<XamlCTask/>` in the Control Gallery sample.
1 parent 6d90430 commit 2131ea1

File tree

4 files changed

+8
-24
lines changed

4 files changed

+8
-24
lines changed

Xamarin.Forms.Build.Tasks/DebugXamlCTask.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,9 @@ public override bool Execute(out IList<Exception> thrownExceptions)
1717
LoggingHelper.LogMessage(Normal, $"{new string(' ', 0)}Preparing debug code for xamlc, assembly: {Assembly}");
1818

1919
var resolver = new DefaultAssemblyResolver();
20-
if (!string.IsNullOrEmpty(DependencyPaths)) {
21-
foreach (var dep in DependencyPaths.Split(';')) {
22-
LoggingHelper.LogMessage(Low, $"{new string(' ', 2)}Adding searchpath {dep}");
23-
resolver.AddSearchDirectory(dep);
24-
}
25-
}
26-
if (!string.IsNullOrEmpty(ReferencePath)) {
27-
var paths = ReferencePath.Replace("//", "/").Split(';');
28-
foreach (var p in paths) {
29-
var searchpath = IOPath.GetDirectoryName(p);
20+
if (ReferencePath != null) {
21+
var paths = ReferencePath.Select(p => IOPath.GetDirectoryName(p.Replace("//", "/"))).Distinct();
22+
foreach (var searchpath in paths) {
3023
LoggingHelper.LogMessage(Low, $"{new string(' ', 2)}Adding searchpath {searchpath}");
3124
resolver.AddSearchDirectory(searchpath);
3225
}

Xamarin.Forms.Build.Tasks/XamlCTask.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,9 @@ public override bool Execute(out IList<Exception> thrownExceptions)
5353
using (var fallbackResolver = DefaultAssemblyResolver == null ? new XamlCAssemblyResolver() : null) {
5454
var resolver = DefaultAssemblyResolver ?? fallbackResolver;
5555
if (resolver is XamlCAssemblyResolver xamlCResolver) {
56-
if (!string.IsNullOrEmpty(DependencyPaths)) {
57-
foreach (var dep in DependencyPaths.Split(';').Distinct()) {
58-
LoggingHelper.LogMessage(Low, $"{new string(' ', 2)}Adding searchpath {dep}");
59-
xamlCResolver.AddSearchDirectory(dep);
60-
}
61-
}
62-
63-
if (!string.IsNullOrEmpty(ReferencePath)) {
64-
var paths = ReferencePath.Replace("//", "/").Split(';').Distinct();
65-
foreach (var p in paths) {
66-
var searchpath = IOPath.GetDirectoryName(p);
56+
if (ReferencePath != null) {
57+
var paths = ReferencePath.Select (p => IOPath.GetDirectoryName(p.Replace("//", "/"))).Distinct();
58+
foreach (var searchpath in paths) {
6759
LoggingHelper.LogMessage(Low, $"{new string(' ', 2)}Adding searchpath {searchpath}");
6860
xamlCResolver.AddSearchDirectory(searchpath);
6961
}

Xamarin.Forms.Build.Tasks/XamlTask.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ public abstract class XamlTask : MarshalByRefObject, ITask
2222
{
2323
[Required]
2424
public string Assembly { get; set; }
25-
public string DependencyPaths { get; set; }
26-
public string ReferencePath { get; set; }
25+
public string[] ReferencePath { get; set; }
2726
[Obsolete("this is no longer used")]
2827
[EditorBrowsable(EditorBrowsableState.Never)]
2928
public int Verbosity { get; set; }

Xamarin.Forms.Xaml.UnitTests/MockCompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static void Compile(Type type, out MethodDefinition methdoDefinition)
2626

2727
var xamlc = new XamlCTask {
2828
Assembly = assembly,
29-
ReferencePath = string.Join(";", refs),
29+
ReferencePath = refs.ToArray(),
3030
KeepXamlResources = true,
3131
OptimizeIL = true,
3232
DebugSymbols = false,

0 commit comments

Comments
 (0)