Skip to content

Commit c1953a5

Browse files
authored
[msbuild] Use ILRepack as a dotnet tool. (#21240)
This is one step towards removing the dependency on having Mono installed during the build. For some reason that also ended up requiring a few nullability issues in the msbuild tests.
1 parent 8106ee6 commit c1953a5

File tree

5 files changed

+40
-33
lines changed

5 files changed

+40
-33
lines changed

.config/dotnet-tools.json

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
"commands": [
88
"t4"
99
]
10+
},
11+
"dotnet-ilrepack": {
12+
"version": "1.0.0",
13+
"commands": [
14+
"ilrepack"
15+
]
1016
}
1117
}
1218
}

msbuild/ILMerge.targets

+3-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
</ItemGroup>
7272
<ItemGroup>
7373
<ReferenceCopyLocalDirs Include="@(ReferenceCopyLocalPaths -&gt; '%(RootDir)%(Directory)')" />
74+
<ReferenceCopyLocalDirs Include="@(ReferencePathWithRefAssemblies -&gt; '%(RootDir)%(Directory)')" />
7475
<ReferenceCopyLocalPaths Remove="@(MergedAssemblies)" />
7576
<LibDir Include="@(ReferenceCopyLocalDirs -&gt; Distinct())" />
7677
</ItemGroup>
@@ -85,9 +86,9 @@
8586
<ILRepackArgs>$(ILRepackArgs) "/lib:$(NetstandardDirectory)"</ILRepackArgs> <!-- This is needed for ilrepack to find netstandard.dll, which is referenced by the System.Text.Json assembly -->
8687
</PropertyGroup>
8788
<PropertyGroup>
88-
<SYSTEM_MONO Condition="'$(SYSTEM_MONO)' == ''">/Library/Frameworks/Mono.framework/Versions/Current/Commands/mono</SYSTEM_MONO>
89+
<LOCAL_DOTNET_PATH Condition="'$(LOCAL_DOTNET_PATH)' == ''">$(MSBuildThisFileDirectory)../builds/downloads/dotnet/dotnet</LOCAL_DOTNET_PATH>
8990
</PropertyGroup>
90-
<Exec Command="$(SYSTEM_MONO) &quot;$(ILRepack)&quot; $(ILRepackArgs)" WorkingDirectory="$(MSBuildProjectDirectory)\$(OutputPath)" StandardErrorImportance="high" StandardOutputImportance="low" ConsoleToMSBuild="true" ContinueOnError="true">
91+
<Exec Command="$(LOCAL_DOTNET_PATH) tool run ilrepack $(ILRepackArgs)" WorkingDirectory="$(MSBuildProjectDirectory)\$(OutputPath)" StandardErrorImportance="high" StandardOutputImportance="low" ConsoleToMSBuild="true" ContinueOnError="true">
9192
<Output TaskParameter="ConsoleOutput" PropertyName="ILRepackOutput" />
9293
<Output TaskParameter="ExitCode" PropertyName="ExitCode" />
9394
</Exec>

tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileAppManifestTaskTests.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void DefaultMinimumOSVersion ()
3636

3737
ExecuteTask (task);
3838

39-
var plist = PDictionary.FromFile (task.CompiledAppManifest.ItemSpec);
39+
var plist = PDictionary.FromFile (task.CompiledAppManifest!.ItemSpec)!;
4040
Assert.AreEqual (task.SdkVersion, plist.GetMinimumOSVersion (), "MinimumOSVersion");
4141
}
4242

@@ -55,7 +55,7 @@ public void MainMinimumOSVersions ()
5555

5656
ExecuteTask (task);
5757

58-
var plist = PDictionary.FromFile (task.CompiledAppManifest.ItemSpec);
58+
var plist = PDictionary.FromFile (task.CompiledAppManifest!.ItemSpec)!;
5959
Assert.AreEqual ("14.0", plist.GetMinimumOSVersion (), "MinimumOSVersion");
6060
}
6161

@@ -81,7 +81,7 @@ public void MultipleMinimumOSVersions ()
8181

8282
ExecuteTask (task);
8383

84-
var plist = PDictionary.FromFile (task.CompiledAppManifest.ItemSpec);
84+
var plist = PDictionary.FromFile (task.CompiledAppManifest!.ItemSpec)!;
8585
Assert.AreEqual ("13.0", plist.GetMinimumOSVersion (), "MinimumOSVersion");
8686
}
8787

@@ -112,7 +112,7 @@ public void SupportedOSPlatformVersion ()
112112

113113
ExecuteTask (task);
114114

115-
var plist = PDictionary.FromFile (task.CompiledAppManifest.ItemSpec);
115+
var plist = PDictionary.FromFile (task.CompiledAppManifest!.ItemSpec)!;
116116
Assert.AreEqual ("11.0", plist.GetMinimumOSVersion (), "MinimumOSVersion");
117117
}
118118

@@ -123,7 +123,7 @@ public void MacCatalystVersionCheck ()
123123
task.SupportedOSPlatformVersion = "14.2";
124124
ExecuteTask (task);
125125

126-
var plist = PDictionary.FromFile (task.CompiledAppManifest.ItemSpec);
126+
var plist = PDictionary.FromFile (task.CompiledAppManifest!.ItemSpec)!;
127127
Assert.AreEqual ("11.0", plist.GetMinimumSystemVersion (), "MinimumOSVersion");
128128
}
129129

@@ -150,7 +150,7 @@ public void XcodeVariables (ApplePlatform platform, bool isSimulator, string exp
150150
task.SdkIsSimulator = isSimulator;
151151
ExecuteTask (task);
152152

153-
var plist = PDictionary.FromFile (task.CompiledAppManifest.ItemSpec);
153+
var plist = PDictionary.FromFile (task.CompiledAppManifest!.ItemSpec)!;
154154
var variables = new string [] {
155155
"DTCompiler",
156156
"DTPlatformBuild",

tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileEntitlementsTaskTests.cs

+23-23
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
namespace Xamarin.MacDev.Tasks {
1313
class CustomCompileEntitlements : CompileEntitlements {
14-
protected override MobileProvision? GetMobileProvision (MobileProvisionPlatform platform, string uuid)
14+
protected override MobileProvision GetMobileProvision (MobileProvisionPlatform platform, string uuid)
1515
{
1616
if (File.Exists (ProvisioningProfile))
1717
return MobileProvision.LoadFromFile (ProvisioningProfile);
1818

19-
return null;
19+
return null!;
2020
}
2121
}
2222

@@ -61,10 +61,10 @@ public void ValidateEntitlement ()
6161
{
6262
var task = CreateEntitlementsTask (out var compiledEntitlements, out var archivedEntitlements);
6363
ExecuteTask (task);
64-
var compiled = PDictionary.FromFile (compiledEntitlements);
65-
Assert.IsTrue (compiled.Get<PBoolean> (EntitlementKeys.GetTaskAllow).Value, "#1");
66-
Assert.AreEqual ("32UV7A8CDE.com.xamarin.MySingleView", compiled.Get<PString> ("application-identifier").Value, "#2");
67-
Assert.AreEqual ("Z8CSQKJE7R", compiled.Get<PString> ("com.apple.developer.team-identifier").Value, "#3");
64+
var compiled = PDictionary.FromFile (compiledEntitlements)!;
65+
Assert.IsTrue (compiled.Get<PBoolean> (EntitlementKeys.GetTaskAllow)?.Value, "#1");
66+
Assert.AreEqual ("32UV7A8CDE.com.xamarin.MySingleView", compiled.Get<PString> ("application-identifier")?.Value, "#2");
67+
Assert.AreEqual ("Z8CSQKJE7R", compiled.Get<PString> ("com.apple.developer.team-identifier")?.Value, "#3");
6868
Assert.AreEqual ("applinks:*.xamarin.com", compiled.GetAssociatedDomains ().ToStringArray ().First (), "#4");
6969
Assert.AreEqual ("Z8CSQKJE7R.*", compiled.GetPassBookIdentifiers ().ToStringArray ().First (), "#5");
7070
Assert.AreEqual ("Z8CSQKJE7R.com.xamarin.MySingleView", compiled.GetUbiquityKeyValueStore (), "#6");
@@ -113,7 +113,7 @@ public void CustomEntitlemements_String (string value)
113113
task.TargetFrameworkMoniker = ".NETCoreApp,Version=v6.0,Profile=maccatalyst";
114114
task.CustomEntitlements = customEntitlements;
115115
ExecuteTask (task);
116-
var compiled = PDictionary.FromFile (compiledEntitlements);
116+
var compiled = PDictionary.FromFile (compiledEntitlements)!;
117117
Assert.AreEqual (value ?? string.Empty, compiled.GetString ("com.xamarin.custom.entitlement")?.Value, "#1");
118118
}
119119

@@ -131,7 +131,7 @@ public void CustomEntitlemements_StringArray ()
131131
task.TargetFrameworkMoniker = ".NETCoreApp,Version=v6.0,Profile=maccatalyst";
132132
task.CustomEntitlements = customEntitlements;
133133
ExecuteTask (task);
134-
var compiled = PDictionary.FromFile (compiledEntitlements);
134+
var compiled = PDictionary.FromFile (compiledEntitlements)!;
135135
var array = compiled.GetArray ("com.xamarin.custom.entitlement");
136136
Assert.NotNull (array, "array");
137137
Assert.AreEqual (new string [] { "A", "B", "C" }, array.ToStringArray (), "array contents");
@@ -154,7 +154,7 @@ public void CustomEntitlemements_StringArray_CustomSeparator (string separator)
154154
task.TargetFrameworkMoniker = ".NETCoreApp,Version=v6.0,Profile=maccatalyst";
155155
task.CustomEntitlements = customEntitlements;
156156
ExecuteTask (task);
157-
var compiled = PDictionary.FromFile (compiledEntitlements);
157+
var compiled = PDictionary.FromFile (compiledEntitlements)!;
158158
var array = compiled.GetArray ("com.xamarin.custom.entitlement");
159159
Assert.NotNull (array, "array");
160160
Assert.AreEqual (new string [] { "A;B;C", "D", "E" }, array.ToStringArray (), "array contents");
@@ -166,7 +166,7 @@ public void AllowJit_Default ()
166166
var task = CreateEntitlementsTask (out var compiledEntitlements);
167167
task.TargetFrameworkMoniker = ".NETCoreApp,Version=v6.0,Profile=maccatalyst";
168168
ExecuteTask (task);
169-
var compiled = PDictionary.FromFile (compiledEntitlements);
169+
var compiled = PDictionary.FromFile (compiledEntitlements)!;
170170
Assert.IsFalse (compiled.ContainsKey (EntitlementKeys.AllowExecutionOfJitCode), "#1");
171171
}
172172

@@ -180,9 +180,9 @@ public void AllowJit_True ()
180180
task.TargetFrameworkMoniker = ".NETCoreApp,Version=v6.0,Profile=maccatalyst";
181181
task.CustomEntitlements = customEntitlements;
182182
ExecuteTask (task);
183-
var compiled = PDictionary.FromFile (compiledEntitlements);
183+
var compiled = PDictionary.FromFile (compiledEntitlements)!;
184184
Assert.IsTrue (compiled.ContainsKey (EntitlementKeys.AllowExecutionOfJitCode), "#1");
185-
Assert.IsTrue (compiled.Get<PBoolean> (EntitlementKeys.AllowExecutionOfJitCode).Value, "#2");
185+
Assert.IsTrue (compiled.Get<PBoolean> (EntitlementKeys.AllowExecutionOfJitCode)?.Value, "#2");
186186
}
187187

188188
[Test]
@@ -195,9 +195,9 @@ public void AllowJit_False ()
195195
task.TargetFrameworkMoniker = ".NETCoreApp,Version=v6.0,Profile=maccatalyst";
196196
task.CustomEntitlements = customEntitlements;
197197
ExecuteTask (task);
198-
var compiled = PDictionary.FromFile (compiledEntitlements);
198+
var compiled = PDictionary.FromFile (compiledEntitlements)!;
199199
Assert.IsTrue (compiled.ContainsKey (EntitlementKeys.AllowExecutionOfJitCode), "#1");
200-
Assert.IsFalse (compiled.Get<PBoolean> (EntitlementKeys.AllowExecutionOfJitCode).Value, "#2");
200+
Assert.IsFalse (compiled.Get<PBoolean> (EntitlementKeys.AllowExecutionOfJitCode)?.Value, "#2");
201201

202202
Assert.That (archivedEntitlements, Does.Not.Exist, "No archived entitlements");
203203
}
@@ -212,7 +212,7 @@ public void AllowJit_None ()
212212
task.TargetFrameworkMoniker = ".NETCoreApp,Version=v6.0,Profile=maccatalyst";
213213
task.CustomEntitlements = customEntitlements;
214214
ExecuteTask (task);
215-
var compiled = PDictionary.FromFile (compiledEntitlements);
215+
var compiled = PDictionary.FromFile (compiledEntitlements)!;
216216
Assert.IsFalse (compiled.ContainsKey (EntitlementKeys.AllowExecutionOfJitCode), "#1");
217217
}
218218

@@ -226,14 +226,14 @@ public void AppIdentifierPrefix ()
226226
task.TargetFrameworkMoniker = ".NETCoreApp,Version=v6.0,Profile=ios";
227227
task.CustomEntitlements = customEntitlements;
228228
ExecuteTask (task);
229-
var compiled = PDictionary.FromFile (compiledEntitlements);
229+
var compiled = PDictionary.FromFile (compiledEntitlements)!;
230230
Assert.IsFalse (compiled.ContainsKey (EntitlementKeys.AllowExecutionOfJitCode), "#1");
231-
var kag = ((PString) compiled ["keychain-access-group"]).Value;
231+
var kag = ((PString?) compiled ["keychain-access-group"])?.Value;
232232
Assert.That (kag, Is.EqualTo ("32UV7A8CDE.org.xamarin"), "value 1");
233233

234-
var archived = PDictionary.FromFile (archivedEntitlements);
234+
var archived = PDictionary.FromFile (archivedEntitlements)!;
235235
Assert.IsTrue (archived.ContainsKey ("keychain-access-group"), "archived");
236-
var archivedKag = ((PString) archived ["keychain-access-group"]).Value;
236+
var archivedKag = ((PString?) archived ["keychain-access-group"])?.Value;
237237
Assert.That (archivedKag, Is.EqualTo ("32UV7A8CDE.org.xamarin"), "archived value 1");
238238
}
239239

@@ -247,14 +247,14 @@ public void TeamIdentifierPrefix ()
247247
task.TargetFrameworkMoniker = ".NETCoreApp,Version=v6.0,Profile=ios";
248248
task.CustomEntitlements = customEntitlements;
249249
ExecuteTask (task);
250-
var compiled = PDictionary.FromFile (compiledEntitlements);
250+
var compiled = PDictionary.FromFile (compiledEntitlements)!;
251251
Assert.IsFalse (compiled.ContainsKey (EntitlementKeys.AllowExecutionOfJitCode), "#1");
252-
var kag = ((PString) compiled ["keychain-access-group"]).Value;
252+
var kag = ((PString?) compiled ["keychain-access-group"])?.Value;
253253
Assert.That (kag, Is.EqualTo ("Z8CSQKJE7R.org.xamarin"), "value 1");
254254

255-
var archived = PDictionary.FromFile (archivedEntitlements);
255+
var archived = PDictionary.FromFile (archivedEntitlements)!;
256256
Assert.IsTrue (archived.ContainsKey ("keychain-access-group"), "archived");
257-
var archivedKag = ((PString) archived ["keychain-access-group"]).Value;
257+
var archivedKag = ((PString?) archived ["keychain-access-group"])?.Value;
258258
Assert.That (archivedKag, Is.EqualTo ("Z8CSQKJE7R.org.xamarin"), "archived value 1");
259259
}
260260
}

tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ResolveNativeReferencesTaskTest.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void Xcode12_x (string targetFrameworkMoniker, bool isSimulator, string a
3939
// in Xcode 12.1+ watchOS does not have an i386 architecture anymore
4040
// on Xcode 12.2+ you get arm64 for all (iOS, tvOS and watchOS) simulators
4141
var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "Resources", "xcf-xcode12.2.plist");
42-
var plist = PDictionary.FromFile (path);
42+
var plist = PDictionary.FromFile (path)!;
4343
var result = ResolveNativeReferences.TryResolveXCFramework (log, plist, "N/A", targetFrameworkMoniker, isSimulator, architecture, out var frameworkPath);
4444
Assert.AreEqual (result, !string.IsNullOrEmpty (expected), "result");
4545
Assert.That (frameworkPath, Is.EqualTo (expected), "frameworkPath");
@@ -52,7 +52,7 @@ public void Xcode12_x (string targetFrameworkMoniker, bool isSimulator, string a
5252
public void PreXcode12 (string targetFrameworkMoniker, bool isSimulator, string architecture, string expected)
5353
{
5454
var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "Resources", "xcf-prexcode12.plist");
55-
var plist = PDictionary.FromFile (path);
55+
var plist = PDictionary.FromFile (path)!;
5656
var result = ResolveNativeReferences.TryResolveXCFramework (log, plist, "N/A", targetFrameworkMoniker, isSimulator, architecture, out var frameworkPath);
5757
Assert.AreEqual (result, !string.IsNullOrEmpty (expected), "result");
5858
Assert.That (frameworkPath, Is.EqualTo (expected), "frameworkPath");

0 commit comments

Comments
 (0)