Skip to content
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

VisualBasicResxGenerator does not consider CustomToolNamespace #7449

Open
mkaring opened this issue Oct 13, 2024 · 0 comments
Open

VisualBasicResxGenerator does not consider CustomToolNamespace #7449

mkaring opened this issue Oct 13, 2024 · 0 comments

Comments

@mkaring
Copy link

mkaring commented Oct 13, 2024

Analyzer

Diagnostic ID: Does not apply - Microsoft.CodeAnalysis.ResxSourceGenerator

Analyzer source

NuGet Package: Microsoft.CodeAnalysis.ResxSourceGenerator

Version: 3.11.0-beta1.24454.1

Describe the bug

The problem occurs with the Assembly resources that can be created by default in a new visual basic project. The following ItemGroup is created for the assembly default resource:

<ItemGroup>
  <EmbeddedResource Update="My Project\Resources.resx">
    <Generator>VbMyResourcesResXFileCodeGenerator</Generator>
    <LastGenOutput>Resources.Designer.vb</LastGenOutput>
    <CustomToolNamespace>My.Resources</CustomToolNamespace>
  </EmbeddedResource>
</ItemGroup>

The problem in the generated resource file is the directory of this resource file. The source generated starts like this:

' <auto-generated/>

Imports System.Reflection


Namespace Global.ClassLib.My Project
    Friend Partial Class Resources
        Private Sub New
        End Sub

This is a syntax error when compiling the source.

Steps To Reproduce

  1. Create a new project for visual basic using the following command line instructions in any empty directory:
dotnet new sln --name Test ;
dotnet new classlib --language VB --framework net8.0 -o ClassLib
dotnet sln add .\ClassLib\ClassLib.vbproj
dotnet add .\ClassLib\ClassLib.vbproj package Microsoft.CodeAnalysis.ResxSourceGenerator --version 3.11.0-beta1.24454.1
  1. Open the newly created solution "Test.sln" in Visual Studio
  2. Right click "ClassLib" in the Solution Explorer and select "Properties" at the very bottom.
  3. Scroll to the very bottom of the opened page to the "resources" section and click the link to create or open the assembly resources
  4. Enable "View all files" in the solution explorer
  5. Find the file "My Project" → Resources.resx → Resources.Designer.vb
  6. Compile everything

Once you do that, you'll get the error:

1>…\ClassLib\obj\Debug\net8.0\Microsoft.CodeAnalysis.ResxSourceGenerator.VisualBasic\Microsoft.CodeAnalysis.ResxSourceGenerator.VisualBasic.VisualBasicResxGenerator\Resources.Designer.vb(6,30): error BC30205: End of statement expected.

Expected behavior

Ideally the source generator picks up the <CustomToolNamespace> and uses it for the namespace part in addition to the RootNamespace.
The expected header for the generated class file is:

' <auto-generated/>

Imports System.Reflection


Namespace Global.ClassLib.My.Resources
    Friend Partial Class Resources
        Private Sub New
        End Sub

Actual behavior

The current output is:

' <auto-generated/>

Imports System.Reflection


Namespace Global.ClassLib.My Project
    Friend Partial Class Resources
        Private Sub New
        End Sub

With "My Project" being a syntax error.

Additional context

The source generator differs in some more points compared to the VbMyResourcesResXFileCodeGenerator. The "old" file generator creates a "Module" instead of a class with some additional properties. There does not seem to be a way for the new source generator to do the same thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant