Skip to content

Commit a6d1421

Browse files
[nativeaot] fix Exists() checks (#112995)
Context: dotnet/android#9846 Trying to build our `Mono.Android-Tests` suite for NativeAOT, it fails with: EXEC Failed to load assembly 'System.IO' Which is caused by passing: --root:System.IO I couldn't find anything in the Android workload that would cause this. It appears the `Microsoft.NETCore.Native.targets` have an issue caused by this specific project: * When adding to `@(_IlcRootedAssemblies)` it does an `Exists()` check * So `Exists('System.IO.Compression')` is called. This is *true* because there is a folder in the working directory named `System.IO.Compression`! https://github.com/dotnet/android/tree/main/tests/Mono.Android-Tests/Mono.Android-Tests/System.IO.Compression * `%(FileName)` is then `System.IO` as `.Compression` is stripped as the `%(Extension)` metadata. I believe the fix here is to use `System.IO.File.Exists()` instead of MSBuild's `Exists()` as it returns `true` for files *and* folders.
1 parent df5f9fd commit a6d1421

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,17 @@ The .NET Foundation licenses this file to you under the MIT license.
218218

219219
<!-- Now process the raw ItemGroup into the form that ILC accepts: assembly names only -->
220220
<!-- Use the logic that ILLinker uses: if the file exists, this is a file name. Otherwise it's an assembly name -->
221-
<_IlcRootedAssemblies Include="@(_IlcRootedAssembliesRaw->'%(Filename)')" Condition="Exists('%(Identity)')" />
222-
<_IlcRootedAssemblies Include="@(_IlcRootedAssembliesRaw)" Condition="!Exists('%(Identity)')" />
223-
<_IlcConditionallyRootedAssemblies Include="@(_IlcConditionallyRootedAssembliesRaw->'%(Filename)')" Condition="Exists('%(Identity)')" />
224-
<_IlcConditionallyRootedAssemblies Include="@(_IlcConditionallyRootedAssembliesRaw)" Condition="!Exists('%(Identity)')" />
225-
<_IlcTrimmedAssemblies Include="@(_IlcTrimmedAssembliesRaw->'%(Filename)')" Condition="Exists('%(Identity)')" />
226-
<_IlcTrimmedAssemblies Include="@(_IlcTrimmedAssembliesRaw)" Condition="!Exists('%(Identity)')" />
227-
<_IlcSingleWarnAssemblies Include="@(_IlcSingleWarnAssembliesRaw->'%(Filename)')" Condition="Exists('%(Identity)')" />
228-
<_IlcSingleWarnAssemblies Include="@(_IlcSingleWarnAssembliesRaw)" Condition="!Exists('%(Identity)')" />
229-
<_IlcNoSingleWarnAssemblies Include="@(_IlcNoSingleWarnAssembliesRaw->'%(Filename)')" Condition="Exists('%(Identity)')" />
230-
<_IlcNoSingleWarnAssemblies Include="@(_IlcNoSingleWarnAssembliesRaw)" Condition="!Exists('%(Identity)')" />
221+
<!-- Use System.IO.File.Exists() to avoid directories-->
222+
<_IlcRootedAssemblies Include="@(_IlcRootedAssembliesRaw->'%(Filename)')" Condition="$([System.IO.File]::Exists('%(Identity)'))" />
223+
<_IlcRootedAssemblies Include="@(_IlcRootedAssembliesRaw)" Condition="!$([System.IO.File]::Exists('%(Identity)'))" />
224+
<_IlcConditionallyRootedAssemblies Include="@(_IlcConditionallyRootedAssembliesRaw->'%(Filename)')" Condition="$([System.IO.File]::Exists('%(Identity)'))" />
225+
<_IlcConditionallyRootedAssemblies Include="@(_IlcConditionallyRootedAssembliesRaw)" Condition="!$([System.IO.File]::Exists('%(Identity)'))" />
226+
<_IlcTrimmedAssemblies Include="@(_IlcTrimmedAssembliesRaw->'%(Filename)')" Condition="$([System.IO.File]::Exists('%(Identity)'))" />
227+
<_IlcTrimmedAssemblies Include="@(_IlcTrimmedAssembliesRaw)" Condition="!$([System.IO.File]::Exists('%(Identity)'))" />
228+
<_IlcSingleWarnAssemblies Include="@(_IlcSingleWarnAssembliesRaw->'%(Filename)')" Condition="$([System.IO.File]::Exists('%(Identity)'))" />
229+
<_IlcSingleWarnAssemblies Include="@(_IlcSingleWarnAssembliesRaw)" Condition="!$([System.IO.File]::Exists('%(Identity)'))" />
230+
<_IlcNoSingleWarnAssemblies Include="@(_IlcNoSingleWarnAssembliesRaw->'%(Filename)')" Condition="$([System.IO.File]::Exists('%(Identity)'))" />
231+
<_IlcNoSingleWarnAssemblies Include="@(_IlcNoSingleWarnAssembliesRaw)" Condition="!$([System.IO.File]::Exists('%(Identity)'))" />
231232
</ItemGroup>
232233

233234
<ItemGroup>

0 commit comments

Comments
 (0)