Skip to content

Commit 99f8990

Browse files
authored
[build] Fix for MSBuild 16.8 (#755)
We have some "clever" code that attempts to determine if it needs to add `Java.Interop/JniEnvironment.g.cs` to `@(Compile)`, since it may already be there because of file globs, if this isn't a clean/initial build. However, this code no longer seems to work under MSBuild 16.8: `$(_AddCompile)` remains `False` and thus the file isn't getting added to the compile on the first build. Instead, use `%(KeepDuplicates)='false'` to do the de-duping for us. The wrinkle is that this file is added as `Java.Interop/JniEnvironment.g.cs` or `Java.Interop\JniEnvironment.g.cs`, depending on host OS, so we need to use `Path.Combine()` to ensure our added file matches the copy from the glob, so the de-dupe will work. Without any de-duping, the build produces a warning: CS2002: Source file 'JniEnvironment.g.cs' specified multiple times.
1 parent 99897b2 commit 99f8990

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

src/Java.Interop/Directory.Build.targets

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@
1616
Inputs="$(_JNIEnvGenPath)"
1717
Outputs="Java.Interop/JniEnvironment.g.cs;$(IntermediateOutputPath)jni.c">
1818
<MakeDir Directories="$(IntermediateOutputPath)" />
19-
<PropertyGroup>
20-
<_AddCompile Condition=" !Exists('Java.Interop/JniEnvironment.g.cs') ">True</_AddCompile>
21-
</PropertyGroup>
2219
<Exec
2320
Command="$(_RunJNIEnvGen) Java.Interop/JniEnvironment.g.cs $(IntermediateOutputPath)jni.c"
2421
/>
2522
<ItemGroup>
26-
<Compile Include="Java.Interop/JniEnvironment.g.cs" Condition=" '$(_AddCompile)' == 'True' " />
23+
<Compile Include="$([System.IO.Path]::Combine('Java.Interop','JniEnvironment.g.cs'))" KeepDuplicates="false" />
2724
</ItemGroup>
2825
</Target>
2926
<Target Name="BuildInteropJar"

0 commit comments

Comments
 (0)