简体   繁体   English

如何从 .net 核心 web Z8A5DA52ED12644721AAZ 项目中删除虚拟添加的 angular 文件

[英]How to remove the virtually added angular files from the .net core web api project

I want to start a new project using asp.net core web.api and angular 9. As a start, I want to create a .net core web api project without MVC or scaffolded angular project. I want to start a new project using asp.net core web.api and angular 9. As a start, I want to create a .net core web api project without MVC or scaffolded angular project. What I also would like is to start the spa when the web.api is launched, the same way it works with a scaffolded create asp.net core web application (version 3.1) with Angular. What I also would like is to start the spa when the web.api is launched, the same way it works with a scaffolded create asp.net core web application (version 3.1) with Angular. I want to use this scaffold as my source, but out of the box, there are some things I don't like about this scaffolded project.我想使用这个脚手架作为我的源代码,但是开箱即用,我不喜欢这个脚手架项目的一些东西。 The version of the angular is 8, not 9 but a simple update could fix that I guess. angular 的版本是 8,而不是 9,但我猜一个简单的更新可以解决这个问题。 The other thing I try to achieve is change the folder structure and replace the angular project out of the web api project.我尝试实现的另一件事是更改文件夹结构并从 web api 项目中替换 angular 项目。

The original folder structure is:原来的文件夹结构是:

Solutionfolder
  |- WebApi project
      |- ClientApi (which contains the angular project)

What I want is:我想要的是:

Solutionfolder
  |- WebApp (which contains the angular project)
  |- WebApi project

As I believe the angular project doesn't belong in the web api project.我相信 angular 项目不属于 web api 项目。 To achieve this, I started a new asp.net core web application with .net core version 3.1 and choosing Angular in the proces and then I did the following steps: To achieve this, I started a new asp.net core web application with .net core version 3.1 and choosing Angular in the proces and then I did the following steps:

  • I moved the ClientApi project next to the WebApi project and renamed it (for this PoC I changed it to ClientApiChanged).我将 ClientApi 项目移到 WebApi 项目旁边并将其重命名(对于此 PoC,我将其更改为 ClientApiChanged)。
  • In my startup.cs I changed the following configurations:在我的 startup.cs 中,我更改了以下配置:
    • configuration.RootPath = "../ClientAppChanged/dist";
    • spa.Options.SourcePath = "../ClientAppChanged";
  • And finally, I changed the spaRoot in the.csproj file: <SpaRoot>..\ClientAppChanged\</SpaRoot>最后,我更改了 .csproj 文件中的 spaRoot: <SpaRoot>..\ClientAppChanged\</SpaRoot>

And this works but the last step seems to cause a nasty side effect: it adds virtually the angular project files to the WebApi project:这可行,但最后一步似乎会引起讨厌的副作用:它实际上将 angular 项目文件添加到 WebApi 项目中:

在此处输入图像描述

So my final step is to get rid of the virtually added files but I cannot figure out why it is added.所以我的最后一步是摆脱虚拟添加的文件,但我不知道为什么要添加它。 My best guess is it got to do with the spaRoot setting in the.csproj file.我最好的猜测是它与 .csproj 文件中的 spaRoot 设置有关。 My question is: why is the files virtually added to the web API project file and how can I stop this?我的问题是:为什么这些文件实际上被添加到 web API 项目文件中,我该如何阻止这个?

After some more searching, I found a topic which helped me in the right direction.经过一番搜索,我找到了一个帮助我朝着正确方向发展的主题。 In the.csproj file, the next line is causing the added files virtually to the project:在 .csproj 文件中,下一行将添加的文件虚拟地添加到项目中:

<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />

After removing this line of code, the files aren't shown anymore as part of the project:删除这行代码后,文件不再作为项目的一部分显示:

在此处输入图像描述

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

相关问题 如何将 Angular 项目添加到现有 .NET 核心 Web ZDB974238714CA8DE634A7CE1D08 项目? - How do I add an Angular project to an exisiting .NET Core Web API project? 使用 Angular 8 和 .Net Core Web API 上传大文件 - Upload Large Files using Angular 8 and .Net Core Web API 如何从.Net Core项目/解决方案中删除.ncrunchproject文件(或任何其他类似的文件) - How to remove .ncrunchproject files (or any other files that are similar) from .Net Core project/solution 如何在 .NET 核心 5 Web ZDB974238714CA8DE634A7CE1D083A1 项目中自动格式化 API 响应? - How to autoformat API response in .NET core 5 Web API project? How to add .net core Web API project to an existing .NET core (3.1) Web Application project? - How to add .net core Web API project to an existing .NET core (3.1) Web Application project? 将文件从 ASP.NET Core web api 发布到另一个 ASP.NET Core web api - Post files from ASP.NET Core web api to another ASP.NET Core web api 从另一个项目初始化ASP.NET Core Web API - Initialize ASP.NET Core Web API from another project Angular 从 .net 核心下载 PDF web api - Angular download PDF from .net core web api 从角度4发布的数据在.net Core Web API中获取为空 - Data that is posted from angular 4 is getting as null in .net core web api 如何在 ASP.NET Core Web API 项目中设置 cookie - How to set a cookie in a ASP.NET Core Web API project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM