Skip to content

Conversation

@jpobst
Copy link
Contributor

@jpobst jpobst commented Dec 7, 2020

We have some "clever" code that attempts to determine if it needs to add Java.Interop/JniEnvironment.g.cs to our compile items, since it may already be there because of file globs, if this isn't a clean run. 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 first run.

Instead we're going to 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 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 CS2002: Source file 'JniEnvironment.g.cs' specified multiple times warning.

@jpobst jpobst marked this pull request as ready for review December 7, 2020 22:27
@jpobst jpobst requested a review from jonpryor December 7, 2020 22:28
Comment on lines -19 to +23
<PropertyGroup>
<_AddCompile Condition=" !Exists('Java.Interop/JniEnvironment.g.cs') ">True</_AddCompile>
</PropertyGroup>
<Exec
Command="$(_RunJNIEnvGen) Java.Interop/JniEnvironment.g.cs $(IntermediateOutputPath)jni.c"
/>
<ItemGroup>
<Compile Include="Java.Interop/JniEnvironment.g.cs" Condition=" '$(_AddCompile)' == 'True' " />
<Compile Include="$([System.IO.Path]::Combine('Java.Interop','JniEnvironment.g.cs'))" KeepDuplicates="false" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an idea, could this file be in $(IntermediateOutputPath)JniEnvironment.g.cs instead?

Then you wouldn't need to worry about it getting automatically included at all? You just need to make sure the file is added to @(FileWrites) where it is generated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just go with what we got for now to get the build fixed.

@jonpryor jonpryor merged commit 99f8990 into master Dec 9, 2020
@jonpryor jonpryor deleted the fix-build branch December 9, 2020 15:14
@jpobst jpobst added this to the 11.1 (16.9 / 8.9) milestone Dec 9, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants