GFlisch / Arc4u.Guidance.Doc

Other
5 stars 1 forks source link

Generated projects have incorrect default namespace #174

Open refactorinc opened 1 year ago

refactorinc commented 1 year ago

Describe the bug Generated projects have incorrect default namespace

To Reproduce Steps to reproduce the behavior:

  1. Create blank solution
  2. Generate guidance solution
  3. Add a new C# class file (visual studio, not guidance)
  4. Observe the new class file has a namespace who doesn't start with CompanyName

Expected behavior New files should specify the correct namespace

Desktop (please complete the following information):

phoogers commented 1 year ago

To add to this - I noticed the same. The guidance should add the intended namespace to all the .csproj files within the solution. For sure not everybody will consistently change their namespaces and it will become a mess

For example, the domain csproj looks like this by default:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
    </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Arc4u.Standard.Data" Version="6.0.12.1" />
  </ItemGroup>

</Project>

It would be better to add the default rootnamespace for the assembly as intended, including the company name:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <RootNamespace>BASENAMESPACEHERE</RootNamespace>
    </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Arc4u.Standard.Data" Version="6.0.12.1" />
  </ItemGroup>

</Project>
maxime-poulain commented 1 year ago

Backing up @phoogers statement.

We updated every csprojfiles in order to include a <RootNamespace> in our csproj to match the generated files's namespace.

A good solution would be to make sure generated csprojfiles have this :

<RootNamespace>[CompanyName}.[ProjectName]</RootNamespace>

That way we could have default namespace equals to something like EG.Core.Business

HaGGi13 commented 4 months ago

Hello, Today (2024-04-22) I encountered the same issue and let me search for it on GitHub. So I ended up here.

May I asking you to explain why the generated namespace does not correspond with the underlying folder structure of the solution. I want to understand the advantages of this approach in relation to the Visual Studio default behavior of keeping the project namespaces in sync with their underlying folder structure.

IMOH a proper solution would be to just create a namespace that represents the current folder structure or vice versa, generate the folder structure to reflect the namespace. This would avoid the tons of IDE0130 warnings after a freshly solution generation and is less confusing. Most of the time the namespaces are used like breadcrumbs to cut down bugs or issues, so they are used to navigate within a solution or folder structure. Using the <RootNamespace> will make live harder.

Only of having possibilities to do stuff, does not mean that it must be used.