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

Duplicate root namespace in settings file with sdk-style project #7102

Closed
Tracked by #8243
tgillbe opened this issue Apr 8, 2021 · 4 comments · Fixed by #8322
Closed
Tracked by #8243

Duplicate root namespace in settings file with sdk-style project #7102

tgillbe opened this issue Apr 8, 2021 · 4 comments · Fixed by #8322
Assignees
Labels
Area-VisualBasic Specific to the VB.NET language. Resolution-Fixed The bug has been fixed, refer to the milestone to see in which release it was fixed. Triage-Investigate Reviewed and investigation needed by dev team
Milestone

Comments

@tgillbe
Copy link

tgillbe commented Apr 8, 2021

Visual Studio Version: 16.9.3

Summary:
When using an SDK-style project and vb.net, the automated tool generates a duplicate root namespace for settings files.

Steps to Reproduce:

  1. Create a new SDK-style project for vb.net:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net472</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
    <StartupObject>Test.Module1</StartupObject>
    <RootNamespace>Test</RootNamespace>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="mscorlib" />
  </ItemGroup>
  <ItemGroup>
    <Compile Update="MySettings.Designer.vb">
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
      <AutoGen>True</AutoGen>
      <DependentUpon>MySettings.settings</DependentUpon>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <None Update="My Project\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
    </None>
    <None Update="MySettings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
      <LastGenOutput>MySettings.Designer.vb</LastGenOutput>
    </None>
  </ItemGroup>
</Project>
  1. Add a new settings file (test file is called MySettings.settings).
  2. Inspect the generated MySettings.Designer.vb file.

Expected Behavior:

MySettings.Designer.vb should not wrap the code in the RootNamespace namespace, as that is automatically done by vb.net. This results in a duplicate namespace (i.e. Test.Test.MySettings).

This is what I expect the MySettings.Designer.vb file to look like:

image

Actual Behavior:

MySettings.Designer.vb has duplicated namespace:

image

User Impact:

Having to manually remove the namespace after saving the settings file or compile errors when referring to classes with their fully qualified name.

The correct code results when the RootNamespace is removed from the vb.net project but then all other classes fall out of the namespace. I'm pretty sure it doesn't do this when you use the legacy project style as the problem only showed up after switching to the SDK-style project.

@jjmew jjmew added Area-VisualBasic Specific to the VB.NET language. Triage-Investigate Reviewed and investigation needed by dev team labels Apr 20, 2021
@jjmew jjmew added this to the 17.0 milestone Apr 20, 2021
@MiYanni MiYanni modified the milestones: 17.0, 17.1 Aug 24, 2021
@melytc melytc modified the milestones: 17.1, 17.2 Mar 4, 2022
@melytc melytc modified the milestones: 17.2, 17.3 Mar 14, 2022
@ocallesp
Copy link
Contributor

ocallesp commented Jun 22, 2022

this still reproes.

The Designer.cs is created in Dotnet ProjectSystem
SettingsSingleFileGeneratorBase.Generate( string wszDefaultNamespace )
and wszDefaultNamespce is coming from CPS

This is the method that generates namespaces in CPS
SingleFileGeneratorService.GetCustomToolNamespaceAsync()

@ocallesp
Copy link
Contributor

@tmeschter

In C Sharp the namespace is added
SettingsCS

and the current behavior in VB is the same
SettingsVB

SettingsSingleFileGenerator adds a namespace to CS and VB.

What I see different is that when you hover your mouse over the class definition, you will see that in VB the namespace appears twice. Have any idea of why in VB this is different ?

image

image

@ocallesp ocallesp self-assigned this Jun 23, 2022
@ocallesp
Copy link
Contributor

  1. Define the right behavior in VB
  2. Investigate (and perhaps this is not us) why we see an incorrect namespace when we hover over the class definition

@kvenkatrajan kvenkatrajan modified the milestones: 17.3, 17.4 Jun 23, 2022
@kvenkatrajan
Copy link
Member

@ocallesp

This is in our codebase, the namespace should be removed (legacy project system does not add additional namespace)

' for VB, we need to generate some code that is fully-qualified, but our generator is always invoked
' without the project's root namespace due to VB convention. If this is VB, then we need to look
' up the project's root namespace and pass that in to Create in order to be able to generate the
' appropriate code.
'
Dim projectRootNamespace As String = String.Empty
If isVB Then
projectRootNamespace = GetProjectRootNamespace()
End If

@kvenkatrajan kvenkatrajan assigned adamint and unassigned ocallesp and melytc Jul 14, 2022
@ghost ghost added the Resolution-Fixed The bug has been fixed, refer to the milestone to see in which release it was fixed. label Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-VisualBasic Specific to the VB.NET language. Resolution-Fixed The bug has been fixed, refer to the milestone to see in which release it was fixed. Triage-Investigate Reviewed and investigation needed by dev team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants