Skip to content

[One .NET] add $(AndroidGenerateResourceDesigner) property #6224

New issue

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

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

Already on GitHub? # to your account

Merged
merged 2 commits into from
Aug 25, 2021

Conversation

jonathanpeppers
Copy link
Member

Fixes: #6198

When migrating Xamarin.Android binding projects to .NET 6, one
difference is that Resource.designer.cs will be generated by .NET 6
class libraries.

There is not currently a way to turn this off, if you pass:

dotnet build -p:AndroidUseIntermediateDesignerFile=false

Then Resources\Resource.designer.cs will be generated instead. There
is no way to prevent this behavior, because $(AndroidResgenFile)
defaults to this value.

To solve cases where you don't want Resource.designer.cs at all:

  1. Remove the $(AndroidResgenFile) default value.
  2. Add a new $(AndroidGenerateResourceDesigner) MSBuild property,
    that seems like it will be a better name for .NET 6.
  3. $(AndroidUseIntermediateDesignerFile) is based on
    $(AndroidGenerateResourceDesigner).

I added a test for the new property.

@jonathanpeppers jonathanpeppers force-pushed the androidgenerateresourcedesigner branch from 3d1a809 to 668e52d Compare August 23, 2021 21:29
Fixes: dotnet#6198

When migrating Xamarin.Android binding projects to .NET 6, one
difference is that `Resource.designer.cs` will be generated by .NET 6
class libraries.

There is not currently a way to turn this off, if you pass:

    dotnet build -p:AndroidUseIntermediateDesignerFile=false

Then `Resources\Resource.designer.cs` will be generated instead. There
is no way to prevent this behavior, because `$(AndroidResgenFile)`
defaults to this value.

To solve cases where you *don't* want `Resource.designer.cs` at all:

1. Remove the `$(AndroidResgenFile)` default value.
2. Add a new `$(AndroidGenerateResourceDesigner)` MSBuild property,
   that seems like it will be a better name for .NET 6.
3. `$(AndroidUseIntermediateDesignerFile)` is based on
   `$(AndroidGenerateResourceDesigner)`.

I added a test for the new property.
@jonathanpeppers jonathanpeppers force-pushed the androidgenerateresourcedesigner branch from 668e52d to 71b87b8 Compare August 24, 2021 03:23
@jonathanpeppers jonathanpeppers marked this pull request as ready for review August 24, 2021 15:25
@jonathanpeppers jonathanpeppers requested a review from jpobst August 24, 2021 15:25
Copy link
Contributor

@jpobst jpobst left a comment

Choose a reason for hiding this comment

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

We should probably add it to this list of things Upgrade Assistant should do for converting bindings projects:

dotnet/upgrade-assistant#657


In Xamarin.Android, Java binding projects did not support generating a `Resource.designer.cs` file.
Since binding projects are just class libraries in .NET 6, this file will be generated. This could
be a breaking change when migrating existing projects.
Copy link
Member

Choose a reason for hiding this comment

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

One request for improvement: please provide an example error message. What should customers be looking for in their migrated projects to know that $(AndroidGenerateResourceDesigner)=false should be set?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added two examples where Resource.designer.cs can break.

@jonpryor jonpryor merged commit 02c3347 into dotnet:main Aug 25, 2021
@jonathanpeppers jonathanpeppers deleted the androidgenerateresourcedesigner branch August 25, 2021 16:59
jonathanpeppers added a commit that referenced this pull request Aug 25, 2021
Fixes: #6198

When migrating Xamarin.Android binding projects to .NET 6, one
difference is that `Resource.designer.cs` will be generated by .NET 6
class libraries.

This can result in build failures, e.g.:

	error CS0101: The namespace 'MyBinding' already contains a definition for 'Resource'

There is not currently a way to turn this off; if you try:

	dotnet build -p:AndroidUseIntermediateDesignerFile=false

Then `Resources\Resource.designer.cs` will be generated instead.
There is no way to prevent this behavior, because
`$(AndroidResgenFile)` defaults to this value.

To solve cases where you *don't* want `Resource.designer.cs` at all:

 1. Remove the `$(AndroidResgenFile)` default value.

 2. Add a new `$(AndroidGenerateResourceDesigner)` MSBuild property,
    that seems like it will be a better name for .NET 6.
    `$(AndroidGenerateResourceDesigner)` defaults to True.

 3. `$(AndroidUseIntermediateDesignerFile)` is based on
    `$(AndroidGenerateResourceDesigner)`.

This way, if a Xamarin.Android binding project is migrated to .NET 6,
the binding project can set `$(AndroidGenerateResourceDesigner)`=False
to prevent `Resource.designer.cs` from being generated, which may
prevent build failures.

I added a test and docs for the new property.
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SDK Binding projects shouldn't have Resource.designer.cs
4 participants