简体   繁体   English

如何更改 .NET Core 项目中“wwwroot”文件夹的图标?

[英]How do you change the icon of the `wwwroot` folder in a .NET Core project?

In Visual Studio 2017, when I want to create an ASP.NET Core Web Application from scratch using either one of these standard .NET Core project templates:在 Visual Studio 2017 中,当我想使用以下任一标准 .NET Core 项目模板从头开始创建 ASP.NET Core Web 应用程序时:

  • Console App (.NET Core)控制台应用程序 (.NET Core)
  • Class Library (.NET Core)类库 (.NET Core)

These project templates;这些项目模板; obviously would not include the wwwroot folder.显然不会包括wwwroot文件夹。 So, when I add the folder to my project it will look like (and behave like) a standard folder:因此,当我将文件夹添加到我的项目时,它将看起来(并且表现得像)一个标准文件夹:

.NET Core 控制台应用程序

When you create it using the ASP.NET Core Web Application project template, the wwwroot folder looks like this:使用ASP.NET Core Web 应用程序项目模板创建它时, wwwroot文件夹如下所示:

ASP.NET 核心 Web 应用程序

Question - Appearance (Icon)问题 - 外观(图标)

How do you change the icon of the wwwroot folder to look like the one found in the ASP.NET Core Web Application project template?如何将wwwroot文件夹的图标更改为在ASP.NET Core Web 应用程序项目模板中找到的图标?


Additional Question - Behavior (Copying Files to Output Directory)附加问题 - 行为(将文件复制到输出目录)
In the standard .NET Core project, I would have to add this to my .csproj file:在标准的 .NET Core 项目中,我必须将它添加到我的.csproj文件中:

<ItemGroup>
  <Content Include="wwwroot\**" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

so that it copies all my files from the wwwroot folder to the output directory similar to the ASP.NET Core Web Application project.以便它将我的所有文件从wwwroot文件夹复制到类似于 ASP.NET Core Web 应用程序项目的输出目录。 I looked in the ASP.NET Core Web Application's .csproj file and didn't see anything like that.我查看了 ASP.NET Core Web 应用程序的.csproj文件,但没有看到类似的内容。

I'm assuming the answer to the main question will also provide the answer for this one, as the project templates are obviously different.我假设主要问题的答案也将为这个问题提供答案,因为项目模板显然不同。 I can't seem to find the resources online to help me manually edit this myself.我似乎无法在网上找到资源来帮助我自己手动编辑它。

Thanks in advance.提前致谢。

After reading this page that announced the new tooling in Visual Studio 2017, I found out that it was in fact possible. 在阅读了宣布Visual Studio 2017中新工具的页面后,我发现它实际上是可行的。

I noticed that the ASP.NET Core Web Application project uses a different value under the Project node in the .csproj file. 我注意到ASP.NET Core Web Application项目在.csproj文件的Project节点下使用了不同的值。

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

Whereas the standard project templates used Microsoft.NET.Sdk like this: 而标准项目模板使用Microsoft.NET.Sdk如下:

<Project Sdk="Microsoft.NET.Sdk"> ← ← ← ← //change this to Microsoft.NET.Sdk.Web

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

</Project>

Once I changed the value to Microsoft.NET.Sdk.Web and saved the csproj file, the project upgraded itself, and the wwwroot folder was added to my project automatically (but excluded) , like this: 一旦我将值更改为 Microsoft.NET.Sdk.Web并保存了csproj文件,项目就自行升级,并且wwwroot文件夹自动添加到我的项目中(但不包括在内) ,如下所示:

第1步

Then I included it into the project and now: 然后我将它包含在项目中,现在:

第2步

Great! 大! I hope this answer helps others. 我希望这个答案有助于其他人。

确保此行包含在下面的ItemGroup中

 <Folder Include="wwwroot\" />

我遇到了同样的问题,但最好不要将其称为问题,因为带有图标的 wwwroot 文件夹和没有图标的文件夹之间没有区别,您必须首先找到文件 yourproject.csproj 文件,它由一些标签填充在这个文件的顶部,你会看到它被赋值的标签,像这样 Sdk=Microsoft.NET.Sdk 尝试像这样重新赋值 Sdk="Microsoft.NET.Sdk.web然后尝试删除不寻常的 wwwroot 文件夹并重新生成文件夹和这次将其命名为 wwwroot 它将具有您喜欢的图标

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .Net Core+React项目如何创建wwwroot文件夹? - How to create a wwwroot folder in .Net Core+React project? 更新到 Asp.Net Core 3 的 Identity 项目提供了 wwwroot 文件夹 - Identity project updated to Asp.Net Core 3 gives wwwroot folder 在IIS .net核心wwwroot上找不到CSS文件夹 - CSS folder not found on IIS .net core wwwroot 在ASP.NET 4.5项目中使用wwwroot文件夹(ASP.NET Core样式) - Using a wwwroot folder (ASP.NET Core style) in ASP.NET 4.5 project 如何使用 controller 或在 ASP.NET Core MVC 中查看 wwwroot 文件夹中的 index.html 文件 - How to render index.html file that is in wwwroot folder using controller or view in ASP.NET Core MVC 如何重命名ASP.NET 5 Web项目中用作Web根的“ wwwroot”文件夹 - How to rename “wwwroot” folder used as web root in ASP.NET 5 web project 文件上传到ASP.NET Core中的wwwroot文件夹 - File upload to wwwroot folder in ASP.NET Core ASP.NET 核心工程:文件夹名发布有什么作用? 这个文件夹是如何生成的? - ASP.NET Core project: what does the folder name publish do? And how is this folder generated? 如何将文件写入.NET Core中的项目文件夹? - How to write a file to a project folder in .NET Core? 我如何在Webjob内的Azure托管ASP .NET Core应用程序的wwwroot文件夹中获取图像文件的路径 - How can i get the path to an image file in wwwroot folder of an azure hosted asp .net core app inside a webjob
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM