Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Add an Option to Disable Avalonia Name Generator Warnings #24

Closed
worldbeater opened this issue Feb 9, 2021 · 2 comments
Closed

Add an Option to Disable Avalonia Name Generator Warnings #24

worldbeater opened this issue Feb 9, 2021 · 2 comments

Comments

@worldbeater
Copy link
Collaborator

worldbeater commented Feb 9, 2021

Since #22 and #23 are merged, and 0.2.0-preview is shipped to NuGet, the generator will warn folks when classes inheriting from the Avalonia.INamed interface cannot be processed. If folks tend to write custom controls without XAML files, e.g. they are binding from code or applying tiny fixes, the generator currently writes the following warnings to console:

CSC : warning AXN0003: The type ExampleView should be declared with the 'partial' keyword as it is either annotated with the [GenerateTypedNameReferences] attribute, or the <AvaloniaNameGenerator> property is set to 'true' in the C# project file (it is set to 'true' by default). In order to skip the processing of irrelevant files, put <AvaloniaNameGenerator>false</AvaloniaNameGenerator> into your .csproj file as <PropertyGroup> descendant and decorate only relevant view classes with the [GenerateTypedNameReferences] attribute.

This happens if we add a similar class to a project with XamlNameReferenceGenerator installed, and don't add a XAML file for it:

public class ExampleView : UserControl { }

So if we add ten classes, we'll get ten warnings, and this can be pretty annoying. Currently, the solution is to put to .csproj:

<PropertyGroup>
    <AvaloniaNameGenerator>false</AvaloniaNameGenerator>
</PropertyGroup>

and to decorate only relevant classes with [GenerateTypedNameReferences] explicitly as stated in README.md https://github.com/AvaloniaUI/Avalonia.NameGenerator#usage-opt-in But probably worth introducing additional MSBuild option e.g. <AvaloniaNameGeneratorWarnings>false</AvaloniaNameGeneratorWarnings> e.g. if this property is set to false, then the source generator will silently skip the classes without XAML files without printing the warnings. Worth leaving the warnings enabled by default because they can help in discovering bugs.

@worldbeater worldbeater added the help wanted Extra attention is needed label Feb 9, 2021
@workgroupengineering
Copy link
Contributor

Hi,
for solve this issue you can add in your project

<PropertyGroup>
   <NoWarn>AXN0003</NoWarn>
<PropertyGroup

@worldbeater
Copy link
Collaborator Author

@workgroupengineering thanks, this looks better! Going to document this soon.

@worldbeater worldbeater removed the help wanted Extra attention is needed label Feb 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants