New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with incremental build of resources (missing EmbeddedResource.LogicalName for __AndroidLibraryProjects__) #1235

Closed
xen2 opened this Issue Jan 25, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@xen2

xen2 commented Jan 25, 2018

Sorry, no clear steps to reproduce. Problem happens after various incremental builds.

_AddLibraryProjectsEmbeddedResourceToProject creates an EmbeddedResource:

Task "CreateItem" (TaskId:5014)
  Task Parameter:Include=obj\Android-OpenGLES\__AndroidLibraryProjects__.zip (TaskId:5014)
  Task Parameter:AdditionalMetadata=LogicalName=__AndroidLibraryProjects__.zip (TaskId:5014)
  Output Item(s): 
      EmbeddedResource=
          obj\Android-OpenGLES\__AndroidLibraryProjects__.zip
                  LogicalName=__AndroidLibraryProjects__.zip (TaskId:5014)

However, if _AddLibraryProjectsEmbeddedResourceToProject inputs/outputs are already up to date, it will add it without the LogicalName:

5>Skipping target "_AddLibraryProjectsEmbeddedResourceToProject" because all output files are up-to-date with respect to the input files.
5>Input files: C:\DEV\xenko2\sources\engine\SiliconStudio.Xenko.Engine\obj\Android-OpenGLES\res\layout\game.xml
5>Output files: obj\Android-OpenGLES\__AndroidLibraryProjects__.zip

result:

EmbeddedResource=
    obj\Android-OpenGLES\__AndroidLibraryProjects__.zip
            OriginalItemSpec=obj\Android-OpenGLES\__AndroidLibraryProjects__.zip
            TargetPath=obj\Android-OpenGLES\__AndroidLibraryProjects__.zip

Then, CreateCSharpManifestResourceName ends up creating a LogicalName which contains the root namespace:

obj\Android-OpenGLES\__AndroidLibraryProjects__.zip
    LogicalName=SiliconStudio.Xenko.obj.Android_OpenGLES.__AndroidLibraryProjects__.zip

As a result, ResolveLibraryProjectImports from Xamarin can't find the expected __AndroidLibraryProjects__.zip file since it has another name.
Resources collides and it results in a runtime crash when loading resource.

@xen2

This comment has been minimized.

xen2 commented Jan 25, 2018

Additional details on MSBuild behavior regarding AdditionalMetadata:

https://social.msdn.microsoft.com/Forums/netframework/en-US/259271d8-a3fc-4a9b-9e3a-fecad8f6f63f/potential-bug-with-createitem-task-and-additionalmetadata?forum=msbuild

Seems like the AdditionalMetadata should always be added, so it could be changed that way:

  • _AddLibraryProjectsEmbeddedResourceToProject outputs something else than EmbeddedResource (i.e. a _LibraryProjectsEmbeddedResource) which can be cached
  • _UpdateAndroidResources (which is always run) can transform the _LibraryProjectsEmbeddedResource into a EmbeddedResource with the proper LogicalName

Another way to fix it is change the logic in ResolveLibraryProjectImports.

@dellis1972

This comment has been minimized.

Contributor

dellis1972 commented Jan 25, 2018

@xen2 are you building with xbuild or msbuild? We are trying to figure out which one has the bug.

@xen2

This comment has been minimized.

xen2 commented Jan 25, 2018

@dellis1972 with MSBuild. I suppose xbuild probably have the same issue, since metadatas are not stored and can't be magically recreated out of nothing on second run.

@dellis1972

This comment has been minimized.

Contributor

dellis1972 commented Jan 25, 2018

@xen2 looks like we need to rework our targets a bit so the target which creates the item already runs but the one that generates the zip still gets skipped. Thanks for the bug report :)

dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Jan 25, 2018

[Xamarin.Android.Build.Tasks] missing EmbeddedResource.LogicalName fo…
…r __AndroidLibraryProjects__

Fixes xamarin#1235

There seems to be a bug in msbuild [1] where if you create
an item inside a task and the task is skipped, the metadata
is not created for the item.

So we get into a situation where our `__AndroidLibraryProjects__.zip`
does not contain the correct LogicalName. As a result our
extraction process cannot find the resource, and builds fail.

This commit spits out the code that created the zip file into
its own target `_CreateManagedLibraryResourceArchive`. This means
we can skip this new target it needed. However the target
which creates the item `_AddLibraryProjectsEmbeddedResourceToProject`
can now run for every build. This will ensure that the metadata is
always created.

Also added a unit test.

[1] https://social.msdn.microsoft.com/Forums/netframework/en-US/259271d8-a3fc-4a9b-9e3a-fecad8f6f63f/potential-bug-with-createitem-task-and-additionalmetadata?forum=msbuild

dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Jan 31, 2018

[Xamarin.Android.Build.Tasks] missing EmbeddedResource.LogicalName fo…
…r __AndroidLibraryProjects__

Fixes xamarin#1235

There seems to be a bug in msbuild [1] where if you create
an item inside a task and the task is skipped, the metadata
is not created for the item.

So we get into a situation where our `__AndroidLibraryProjects__.zip`
does not contain the correct LogicalName. As a result our
extraction process cannot find the resource, and builds fail.

This commit spits out the code that created the zip file into
its own target `_CreateManagedLibraryResourceArchive`. This means
we can skip this new target it needed. However the target
which creates the item `_AddLibraryProjectsEmbeddedResourceToProject`
can now run for every build. This will ensure that the metadata is
always created.

Also added a unit test.

[1] https://social.msdn.microsoft.com/Forums/netframework/en-US/259271d8-a3fc-4a9b-9e3a-fecad8f6f63f/potential-bug-with-createitem-task-and-additionalmetadata?forum=msbuild

jonpryor added a commit that referenced this issue Feb 2, 2018

[Xamarin.Android.Build.Tasks] LogicalName & __AndroidLibraryProjects__ (
#1239)

[Xamarin.Android.Build.Tasks] LogicalName & __AndroidLibraryProjects__

Fixes: #1235

There seems to be a [bug in msbuild][1] where if you create an item
inside a task and the task is skipped, the metadata is not created
for the item.

We get into a situation where `__AndroidLibraryProjects__.zip`
does not contain the correct `%(EmbededResource.LogicalName)` value.
As a result the extraction process cannot find the resource, and
builds fail.

Fix this by splitting out the code that created the zip file into a
new `_CreateManagedLibraryResourceArchive` target. This allows us to
skip this new target if needed. However the
`_AddLibraryProjectsEmbeddedResourceToProject` target which creates
the item can now run for every build. This will ensure that the
metadata is always created.

Add a unit test.

[1]: https://social.msdn.microsoft.com/Forums/netframework/en-US/259271d8-a3fc-4a9b-9e3a-fecad8f6f63f/potential-bug-with-createitem-task-and-additionalmetadata?forum=msbuild

xen2 added a commit to SiliconStudio/xenko that referenced this issue Apr 2, 2018

[Build] Workaround for xamarin/xamarin-android#1235 (Android resource…
…s not being properly merged in incremental build)


# Original commit: 'ff2974f2fa8f26fb0723f8cf5b9d657573fc6259'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment