文件可以嵌套在 .NET Core(非 ASP.NET Core)项目的 VS2017 解决方案资源管理器中吗? [英] Can files be nested in VS2017 Solution Explorer for .NET Core (non-ASP.NET Core) projects?

查看:15
本文介绍了文件可以嵌套在 .NET Core(非 ASP.NET Core)项目的 VS2017 解决方案资源管理器中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在老派"的 MSBuild 项目中——例如 VS2017 中的 Windows 窗体仍在使用——文件可以通过 csproj 文件中的 DependentUpon 项嵌套".

In "old school" MSBuild projects - as still used by Windows Forms in VS2017 for example - files could be "nested" via a DependentUpon item in the csproj file.

我用它在 Noda Time 中将单元测试分组在一起,例如

I used this to group unit tests together in Noda Time, e.g.

<Compile Include="LocalDateTest.PeriodArithmetic.cs">
  <DependentUpon>LocalDateTest.cs</DependentUpon>
</Compile>

这导致了易于导航的测试:

That led to easily-navigable tests:

在迁移到 .NET Core 的 project.json 时,我故意丢失"了此功能,但希望在转换为 MSBuild 时它会恢复.但是,看起来基于 .NET Core SDK 的 MSBuild 项目(根元素 <Project Sdk="Microsoft.NET.Sdk">)在 Visual Studio 2017 中没有得到相同的处理,即使 ItemGroup 是手动添加的,其元素与old school"项目相同.

I knowingly "lost" this feature when moving to project.json for .NET Core, but had hoped it would return when converting to MSBuild. However, it looks like MSBuild projects based on the .NET Core SDK (root element <Project Sdk="Microsoft.NET.Sdk">) don't get the same treatment in Visual Studio 2017, even if an ItemGroup is added manually with the same elements as the "old school" project.

ASP.NET Core 项目接收到缩小 CSS 和 Javascript 的自动嵌套,但不清楚如何将其应用于 .NET Core 库项目中的 C#.

ASP.NET Core projects receive automatic nesting for minified CSS and Javascript, but it's not clear how to apply that to C# in .NET Core library projects.

推荐答案

我让它在我的一个 Microsoft.NET.Sdk 风格的项目中使用类似于以下内容:

I have it working in one of my Microsoft.NET.Sdk-style projects using something similar to the following:

<ItemGroup>
  <Compile Update="LocalDateTest.*.cs">
    <DependentUpon>LocalDateTest.cs</DependentUpon>
  </Compile>
</ItemGroup>

这里的技巧是使用 Update 而不是 Include.这是因为隐式项目来自在主项目之前导入的 props 文件.额外的 Include 不会影响已包含的文件,但可以使用 Update 对其进行修改.

The trick here is to use Update instead of Include. This is because the implicit items are coming from a props file that is imported before the main project. An additional Include won't affect files that are already included, but they can be modified using Update.

这篇关于文件可以嵌套在 .NET Core(非 ASP.NET Core)项目的 VS2017 解决方案资源管理器中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆