VisualBasicResxGenerator does not consider CustomToolNamespace
mkaring opened this issue · 0 comments
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
- 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
- Open the newly created solution "Test.sln" in Visual Studio
- Right click "ClassLib" in the Solution Explorer and select "Properties" at the very bottom.
- Scroll to the very bottom of the opened page to the "resources" section and click the link to create or open the assembly resources
- Enable "View all files" in the solution explorer
- Find the file "My Project" → Resources.resx → Resources.Designer.vb
- 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.