在平台和技术之间移植.NET代码时的名称空间和汇编名称

发布于 2025-01-27 02:33:48 字数 613 浏览 4 评论 0原文

我有一些(超过50个).NET框架组件,这些组件我随着时间的推移而开发的。我一直遵循约定在应用程序中的root名称空间之后命名我的汇编。例如,我有一个名为bundt的应用程序,因此其根名称空间为 incipit.bundt 。此应用程序中的汇编被命名为 incipit.bundt.modelingengine incipit.bundt.modeldesigner

。此外,其中一些组件是Winforms应用程序,我将移植到WPF。我的目的是将两个版本的旧版本(旧版本)保留,并在不同的情况下使用它们。

我不确定在移植时应如何处理命名空间和汇编名称。我应该将它们保持不变,还是将它们重命名以反映新平台(核心而不是框架)或技术(WPF而不是Winforms)?

例如,我想将 incipit.bundt.modelingengine 库从.NET Framework到.NET Core。 我应该保留相同的名称空间和汇编名称,还是应该更改它?净核心,使其成为WPF应用程序。同样,我是否应该更改名称空间和组装名称以反映这一点?

对移植最佳实践的任何指示都会非常欢迎。谢谢。

I have a few (over 50) .NET Framework assemblies that I've developed over time. I've always followed the convention to name my assemblies after the root namespace in the application. For example, I have an app called Bundt, so its root namespace is Incipit.Bundt. Assemblies in this application are named Incipit.Bundt.ModellingEngine, Incipit.Bundt.ModelDesigner, etc.

Now I am planning to port some of this code to .NET Core. In addition, some of these assemblies are WinForms applications, which I will be porting to WPF. My intention is to keep both versions of the software, the old and the new, and use them in different scenarios.

I am not sure how namespaces and assembly names should be handled when porting. Should I keep them the same, or should I rename them to reflect the new platform (Core rather than Framework) or technology (WPF rather than WinForms)?

For example, I want to port the Incipit.Bundt.ModellingEngine library from .NET Framework to .NET Core. Should I keep the same namespace and assembly name, or shall I change it? Similarly, I want to port the Incipit.Bundt.ModelDesigner WinForms executable from .NET Framework to .NET Core, and make it a WPF application. Again, should I change the namespace and assembly names to reflect this?

Any pointers to porting best practices will be very welcome. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ヤ经典坏疍 2025-02-03 02:33:48

问题1

我应该保留相同的名称空间和汇编名称,还是要更改它?

让我们将这个问题分为两个:

  • 如果我使用相同的命名,可能会导致什么问题?
  • 哪个命名将在消费者侧产生更多工作?

让我们从前一个开始。不太可能有人想在同一应用程序中使用您的两个组件

  • ,要么选择旧的程序或新的组件,
  • 因此这不会引起汇编模棱两可,

而后者却呢?假设您的移植库可以支持.NET标准1.2。这使我们可以在.NET框架4.6+应用程序中使用此库。

  • 如果该应用程序可以升级而无需任何命名引起打破变化,那么
  • 如果应用程序升级需要使用语句重构,那

是最好的。 href =“ https://learn.microsoft.com/en-us/dotnet/standard/net-antard?tabs=net--stand-2-2-0” rel =“ nofollow noreferrer”>。净标准2.0 (以4.6.1+ .NET FW为支持的应用程序)然后有很大的机会贬低旧库并在新库中使用新图书馆。

问题2

我应该更改命名空间和汇编名称以反映这一点吗?

据我了解,您无法在Winforms应用程序中使用新库,也不能在WPF中使用旧库。因此,它们不能在同一应用程序中使用。

这个问题是更多基于意见的恕我直言。您绝对可以使用相同的名称,不会造成任何危害。但是,如果您将其重命名,那么它可以在应该使用的地方清楚一下。

问题3

我提出了这个问题

如果我通过nugets发布这些组件怎么办?

在这种情况下,如果您想使用相同的名称,可能会导致问题,因为您不能拥有具有相同名称的多个Nuget软件包。

如何解决这个问题?以下是选项:

  • 使用相同的程序集和名称空间名称,但通过 .nuspec file
  • 为新的移植库使用不同的主要版本

Question #1

Should I keep the same namespace and assembly name, or shall I change it?

Let's split this question to two:

  • What problems could it cause if I would use the same naming?
  • Which naming would generate more work on the consumer-side?

Let's start with the former one. It is unlikely that someone wants to use both of your assemblies in the same application

  • Either choose the old one or the new one
  • So, this could not cause assembly ambiguity

What about the latter one? Let's suppose that your ported library can support .NET Standard 1.2. That allows us to use this library in a .NET Framework 4.6+ applications.

  • If that application can upgrade without any naming caused breaking change then that's the best
  • If the application upgrade requires refactoring on the using statements then that's not that good

Side-note: If you can port your library to .NET Standard 2.0 (which supports apps with 4.6.1+ .NET FW) then there is a good chance to deprecate the old library and use everywhere the new one.

Question #2

Should I change the namespace and assembly names to reflect this?

As far as I understand your example you can't use the new library in Winforms application and you can't use the old one in WPF. So, they can't be used in the same application.

This question is more opinion-based IMHO. You can definitely use the same name and will not cause any harm. But if you would rename it then that could give clarity where it suppose to be used.

Question #3

This question is raised by me

What if I publish these assemblies via nugets?

Well in this case it can cause problems if you would like to use the same name, because you can't have multiple nuget packages with the same name.

How to solve this problem? Here are the options:

  • Use the same assembly and namespace names but use different nuget package name via the .nuspec file
  • Use different major version for the new ported library
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文