Visual Studio 2022 – 嵌套部分类(文件)

huangapple go评论71阅读模式
英文:

Visual Studio 2022 - Nesting partial classes (files)

问题

在我的解决方案中,我注意到部分类的嵌套仅适用于 Microsoft.NET.Sdk.Web 项目。对于其他项目 (Microsoft.NET.Sdk),它不起作用。有谁知道这方面的情况吗?

编辑:我发布了 SDK,因为我认为这是原因。我创建了一个新的解决方案,控制台应用程序 (Microsoft.NET.Sdk),尝试创建部分类,仍然无法嵌套文件。

编辑 2:在将以下内容添加到 .csproj 文件后,现在已嵌套。

<ItemGroup>
    <Compile Update=".\Services\CatalogService.*.cs">
        <DependentUpon>.\Services\CatalogService.cs</DependentUpon>
    </Compile>
</ItemGroup>

尽管如此,问题仍然存在...

英文:

I noticed that, in my solution, nesting partial classes is only working for Microsoft.NET.Sdk.Web project.
For the rest of the projects (Microsoft.NET.Sdk) it is not working.
Does anyone know anything about this?


Edit: I posted the SDK because I think that is the reason. I created a new solution, Console App (Microsoft.NET.Sdk) and tried creating partial classes, still doesn't nest the files.

Visual Studio 2022 – 嵌套部分类(文件)

Visual Studio 2022 – 嵌套部分类(文件)


Edit 2
After adding the following to the .csproj file, it is now nested.

&lt;ItemGroup&gt;
	&lt;Compile Update=&quot;.\Services\CatalogService.*.cs&quot;&gt;
		&lt;DependentUpon&gt;.\Services\CatalogService.cs&lt;/DependentUpon&gt;
	&lt;/Compile&gt;
&lt;/ItemGroup&gt;  

Though, the question still remains...

答案1

得分: 3

基于Jimmy在评论中提到的文档,我在我的VS2022中进行了测试,结果表现良好。首先,嵌套部分类适用于Microsoft.NET.Sdk.Web和其他项目(Microsoft.NET.Sdk)。您应该在解决方案资源管理器中检查“文件嵌套选项”。

Visual Studio 2022 – 嵌套部分类(文件)

以下是嵌套文件的几种方法。

  1. 当您选择“默认”时,如果没有为特定项目类型存在设置,则项目中的文件不会被嵌套。您应该通过右键单击项目控制台应用程序(Microsoft.NET.Sdk)的上下文菜单来创建项目特定的设置,并使用pathSegment来设置规则:
    例如:

    "pathSegment": {
         "add": {
           ".*": [
             ".cs",
           ]
         }
       }
    

结果

Visual Studio 2022 – 嵌套部分类(文件)

pathSegment:使用此类型的规则将Catelog.Paged.cs嵌套在Catelog.cs下。

  1. 当您选择“Web”时,此选项将应用Web文件嵌套行为到当前解决方案中的所有项目。

  2. 为解决方案自定义文件嵌套。在解决方案资源管理器中选择“添加自定义设置”。您可以添加尽可能多的自定义文件嵌套设置,这类似于方法1。

英文:

Based on the documentation mentioned by Jimmy in comment, I tested in my VS2022 and it worked well.Firstly, nesting partial classes work for both Microsoft.NET.Sdk.Web and the rest of the projects (Microsoft.NET.Sdk) .You should check File nesting options in solution explorer.

Visual Studio 2022 – 嵌套部分类(文件)

Here’re several methods to nest files.

1 when you select Default, if no settings exist for a given project type, then no files in the project are nested. You should create project-specific settings through the right-click menu (context menu) of the project console App (Microsoft.NET.Sdk).And use pathSegment to set the rules:
 For example

&quot;pathSegment&quot;: {
        &quot;add&quot;: {
          &quot;.*&quot;: [
            &quot;.cs&quot;,
          ]
        }
      }

RESULT

Visual Studio 2022 – 嵌套部分类(文件)

pathSegment: Use this type of rule to nest Catelog.Paged.cs under Catelog.cs

2 when you select Web: This option applies the Web file nesting behavior to all the projects in the current solution.

3 customize file nesting for a solution. Select Add Custom Setting in solution explorer. You can add as many custom file nesting settings as you like. It’s similar to method 1.

答案2

得分: 1

这仍然在这里不起作用...

我有一个.NET 4.8类库,但没有部分.cs类嵌套在其父类下。

我已尝试您上面写的所有内容,但没有任何效果。

英文:

This still does not work here...

I have a .Net 4.8 Class Libray and no partial .cs class get's nested under it's parent.

I have tried all you wrote above but nothing does work.

huangapple
  • 本文由 发表于 2023年2月6日 18:42:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75360240.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定