c# - 如何永久重命名 C# 项目的 Properties 命名空间

标签 c# visual-studio namespaces rename

在另一个项目中,我有一些使用名称 Properties 的类,因此当预生成的“设置”和“资源”属性命名空间妨碍时,使用它们会变得很麻烦。有没有办法强制此命名空间在修改资源或设置后仍保持重命名?

以下是导致问题的文件。

Resources.Designer.cs

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace ProjectNamespace.Properties {
    using System;

Settings.Designer.cs

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace ProjectNamespace.Properties {

如果还不清楚。我想重命名 Properties,而不是 ProjectName

最佳答案

听起来您已经通过项目属性窗口的相应选项卡(您可以在其中添加这些项目的默认文件)添加了 SettingsResources 文件。当您这样做时,名称 .Properties 将附加到命名空间,并且它们组织在 Solution Explorer< 中项目的 Properties 节点下:

enter image description here

相反,请尝试将它们添加为单独的项目项。为此,请右键单击您的项目,选择Add --> New Item,选择Visual C# Items 下的General 标题,然后然后您可以添加新的资源文件和/或设置文件:

enter image description here

这些文件将像任何其他项目一样添加到您的项目中(不在 Properties 节点下),并将使用项目的默认命名空间,并且不会添加 .Properties 到它:

enter image description here

关于c# - 如何永久重命名 C# 项目的 Properties 命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47319295/

相关文章:

c# - 在消息框中插入图像

c# - 无法将 "Microsoft.Azure.Devices"包的 azure sdk 日志获取到控制台

visual-studio - 如何在 Visual Studio 类设计器中更改类的 z 顺序?

visual-studio - 为什么不是所有 NUnit 测试类别都显示在测试资源管理器中?

visual-studio - 如何阻止 Visual Studio 将程序集添加到我的 web.config?

c# - 当不是 url 时,使用多个命名空间的 XML 选择

c++ - 使用 namespace 行为背后的基本原理

c# - using block 是否使对象保持事件状态?

c# - 如何让 Entity Framework 在 1 :1 relationship? 上执行联接查询

r - "import as"在 R